P-Switch effect Toggles on and off during a level

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Chilly14
Snifit
Snifit
Posts: 230
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

P-Switch effect Toggles on and off during a level

Postby Chilly14 » Mon Oct 07, 2019 3:50 pm

How can I get the P-Switch effect to toggle on and off throughout a level without using any switches or blocks? And while the effect is taking place, how do I disable the music?

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9491
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: P-Switch effect Toggles on and off during a level

Postby Enjl » Mon Oct 07, 2019 3:56 pm


Chilly14
Snifit
Snifit
Posts: 230
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: P-Switch effect Toggles on and off during a level

Postby Chilly14 » Mon Oct 07, 2019 4:09 pm

Thank you!

Added in 11 minutes 47 seconds:
Actually, it's not working. It's telling me that the error expected "=" near "end".

Added in 2 hours 45 minutes 50 seconds:
Here's the error:
Image

Hoeloe
Foo
Foo
Posts: 1442
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: P-Switch effect Toggles on and off during a level

Postby Hoeloe » Mon Oct 07, 2019 9:24 pm

You'll need to show your code, otherwise we can't tell you what the problem is.

Chilly14
Snifit
Snifit
Posts: 230
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: P-Switch effect Toggles on and off during a level

Postby Chilly14 » Mon Oct 07, 2019 10:27 pm


Hoeloe
Foo
Foo
Posts: 1442
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: P-Switch effect Toggles on and off during a level

Postby Hoeloe » Mon Oct 07, 2019 11:02 pm

So, the issue here is that you've misunderstood the documentation. Take a look at this again:

Misc.doPSwitchRaw(boolean activate)

See how it has 1) brackets after it, and 2) something inside those brackets?

The brackets tell the program this is a function call - that means you're asking the program to do something (not just moving data around). The thing inside the brackets is an argument - that tells it some information about what you want it to do (and the documentation also tells you the type of data it expects). In this case, an example might be:

Misc.doPSwitchRaw(true)

which would enable the p-switch effect.

Chilly14
Snifit
Snifit
Posts: 230
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: P-Switch effect Toggles on and off during a level

Postby Chilly14 » Tue Oct 08, 2019 11:25 am

Still not working, here's the code again:

https://hastebin.com/ohonanaboz.rb

Hoeloe
Foo
Foo
Posts: 1442
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: P-Switch effect Toggles on and off during a level

Postby Hoeloe » Tue Oct 08, 2019 12:13 pm

What is data here? You never define that, so you'll probably get an error saying you were "attempting to index a nil value" - that is, you tried to do:

data.timer

when data doesn't exist. That doesn't make sense, since it can't look for the timer field inside something non-existent, so it'll just error.


Speaking of which, you don't actually need to use a timer at all here. You can just check lunatime.tick(), which will give you the current game tick.

Chilly14
Snifit
Snifit
Posts: 230
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: P-Switch effect Toggles on and off during a level

Postby Chilly14 » Tue Oct 08, 2019 12:22 pm

Now it works! Thanks so much!


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest