Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
DisasterMaster
- Blooper

- Posts: 164
- Joined: Fri Jan 31, 2020 10:01 pm
Postby DisasterMaster » Sat Jun 05, 2021 6:54 pm
Is it possible to use the original Switch Blocks (170, 173, 176, & 179) to alter custom blocks (751-1000)? If it is, what coding would you use to allow the custom blocks to be toggled back-and-forth?
For example, toggling a Yellow Switchable Hurt Block to become an unhittable outline and vice-versa.

|
|
|
|
|
|
|
|
|
-
FirestarPlays
- Chain Chomp

- Posts: 303
- Joined: Tue Feb 28, 2017 1:26 pm
- Pronouns: he/him
Postby FirestarPlays » Sun Jun 06, 2021 10:46 am
DisasterMaster wrote: ↑Sat Jun 05, 2021 6:54 pm
Is it possible to use the original Switch Blocks (170, 173, 176, & 179) to alter custom blocks (751-1000)? If it is, what coding would you use to allow the custom blocks to be toggled back-and-forth?
For example, toggling a Yellow Switchable Hurt Block to become an unhittable outline and vice-versa.
You can definitely do that with layers and events. Not sure about lua, but it could certainly be done with layers and events.
|
|
|
|
|
|
|
|
|
-
Murphmario
- 2025 Egg Hunter

- Posts: 2389
- Joined: Fri Dec 20, 2013 7:07 pm
- Pronouns: he/him
Postby Murphmario » Sun Jun 06, 2021 1:12 pm
There's a basegame library called Switchcolors, which has a function that can be called based on whether or not a switch is turned on or not. Info on it is in the handbook.
|
|
|
|
|
|
|
|
|
-
DisasterMaster
- Blooper

- Posts: 164
- Joined: Fri Jan 31, 2020 10:01 pm
Postby DisasterMaster » Sun Jun 06, 2021 4:03 pm
Murphmario wrote: ↑Sun Jun 06, 2021 1:12 pm
There's a basegame library called Switchcolors, which has a function that can be called based on whether or not a switch is turned on or not. Info on it is in the handbook.
Found it, thank you.
I can switch them back and forth now, but I can only make the block insta-kill with the "Lava=true" condition. Is there a condition that makes them only do 1 damage at a time?
|
|
|
|
|
|
|
|
|
-
Murphmario
- 2025 Egg Hunter

- Posts: 2389
- Joined: Fri Dec 20, 2013 7:07 pm
- Pronouns: he/him
Postby Murphmario » Mon Jun 07, 2021 12:08 am
DisasterMaster wrote: ↑Sun Jun 06, 2021 4:03 pm
Murphmario wrote: ↑Sun Jun 06, 2021 1:12 pm
There's a basegame library called Switchcolors, which has a function that can be called based on whether or not a switch is turned on or not. Info on it is in the handbook.
Found it, thank you.
I can switch them back and forth now, but I can only make the block insta-kill with the "Lava=true" condition. Is there a condition that makes them only do 1 damage at a time?
Call collidesWith(player) for each direction and put player:hurt for each.
|
|
|
|
|
|
|
|
|
-
DisasterMaster
- Blooper

- Posts: 164
- Joined: Fri Jan 31, 2020 10:01 pm
Postby DisasterMaster » Mon Jun 07, 2021 10:24 am
Murphmario wrote: ↑Mon Jun 07, 2021 12:08 am Call collidesWith(player) for each direction and put player:hurt for each.

Thanks again, got it to work fully.
For some strange reason I thought you could just put "harm=true" or "danger=true". I must be losing it.
|
|
|
|
|
|
|
|
|
-
DisasterMaster
- Blooper

- Posts: 164
- Joined: Fri Jan 31, 2020 10:01 pm
Postby DisasterMaster » Fri Jun 25, 2021 10:11 am

Ok. Maybe I don't have it. Now only the blue blocks change and they change when hitting both switch colors.
Here's the Lua I have for the Yellow Blocks (ids 998 & 999):
function switchcolors.onSwitch(yellow)
if color == yellow then
switchcolors.switch(998, 999)
end
And for the Blue Blocks (ids 996 & 997):
function switchcolors.onSwitch(blue)
if color == blue then
switchcolors.switch(996, 997)
end
Perhaps someone knows what I'm doing wrong.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Fri Jun 25, 2021 10:50 am
Just writing out words in code makes it treat that word as a variable - you need to wrap words you want to be treated as literal text in quotes. You also fundamentally misunderstand how event functions work. You can't write something like "onSwitch(yellow)" to make it only run when yellow switches are pressed - onSwitch is called any time any switch is pressed, and the argument is a variable that contains what colour wat hit, that you can then check. For example:
Code: Select all function switchcolors.onSwitch(color)
if color == "red" then
--hit red switch
elseif color == "green" then
--hit green switch
end
end
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 3 guests
|