Page 1 of 1

Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Sat Jun 05, 2021 6:54 pm
by DisasterMaster
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.
Image

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Sun Jun 06, 2021 10:46 am
by FirestarPlays
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.
Image
You can definitely do that with layers and events. Not sure about lua, but it could certainly be done with layers and events.

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Sun Jun 06, 2021 1:12 pm
by Murphmario
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.

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Sun Jun 06, 2021 4:03 pm
by DisasterMaster
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?

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Mon Jun 07, 2021 12:08 am
by Murphmario
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.

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Mon Jun 07, 2021 10:24 am
by DisasterMaster
Murphmario wrote:
Mon Jun 07, 2021 12:08 am
Call collidesWith(player) for each direction and put player:hurt for each.
Image
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.

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Fri Jun 25, 2021 10:11 am
by DisasterMaster
Image
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.

Re: Using The Original Switch Blocks (170,173,176,179) With New Custom Blocks

Posted: Fri Jun 25, 2021 10:50 am
by Hoeloe
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