Toggling between two states (Solved)

I’ve posted on here about 3 times today so I do apologize but I guess today was my “bug” day with issues I encountered. I’m not great with flow lab so bear with me if this is a simple fix.

Working on a light effect and used the simple lighting effect by grazer to have a starting position on the code rather than starting from scratch. My level is designed so that when you enter a certain area, the lighting effect “turns on” and your vision is reduced. So, there’s indicators at each exit/entrance to toggle this effect on and off.


Those “torches” in the top left are the indicator block (in the final they will be invis). Sorry the pic is dark I have a fade from black mechanic, the lighting effect, and black blocks to block off vision to certain areas so everything is basically covered!

//explaining my thought process behind the code
And here is the dreadful code in question. On collision with the player (puzzle cat2) it goes through the on switch which then turns off for a brief time so the collision doesn’t enable multiple times when going through. Then gets the value stored in the var state. That value is then sent through another switch (explain in a sec) that goes through two filters (i know they are redundant and I could have just used one but id rather look at it in this format) If that state var is 0 (meaning off) it then sends a msg to the light effect to turn on, waits a small amount of time then gets the number 1 and sets the state var to 1, indicating on. And this process would be repeated if state was originally in 1.

The problem is that it does work like 90% of the time, but with that 10% I can’t explain why it’s not working as the code isn’t suddenly changing on me and it’s random when it does happen.
The timers are all there as I initially thought the problem was due to timing so I spaced out the changes but still nothing. I also know there’s a toggle behavior but all my research and testing has only made me more confused on what it actually does so if there’s an easier solution with the toggle I’m all ears.

Heres a link to a vid of the issue:https://kapwi.ng/c/m1JEKbu2
Or if you want to try yourself:https://flowlab.io/game/play/1653402
Instructions if doing yourself: Go to Prison level 8 (NOT the intro) in edit, start, go right, suffer through dialogue, go left and hit top left cracked blocks twice and just interact with those torches. If you just walk right you’ll find the torches I’m having a problem with even though they are the same object. Just be careful when going down if the white cat “sees” you level restarts.

Let me know if anyone sees any issues. Its currently 1 am and I’m a bit deprived of sleep so the second this is posted assume I am already sleeping and will respond in the morning :slight_smile:

4 Likes

have you tried using a proximity trigger? if the character is in said proximity trigger the light affect is switched to on and if the character is not in the proximity trigger then it turns the switch off ill make an example to show you what I mean

1 Like

ok here is an example that works. when you get 3 blocks from the floating gray block it makes the shader turn on. most of the code is in the shader itself but there is a bit of code in the character and the proximity block, look at all of the code to try to understand what is happening. the reason it would only sometimes work was because of the timers try to use the nor logic gate instead. hope it helps you with what you are doing! Example
P.S. if you don’t understand somthing or you need help with anything else contact me and ill help in any way i can.

2 Likes

I never thought of it that way! I actually when you first responded had just found a solution :sweat_smile: Instead of just one block with ALL the behavior, I have 3, one is an on indicator, one an off, and one that holds the main var of state. They enable on and off depending on what state is and Im happy with where its at. Sounds weird but it works surprisingly!
But!! I think if I had read this before I started on this solution I would have used this too. The only drawback for this one would be i would have to have multiple of the blocks as the area i want dark isn’t a perfect box/area but a lot of boxes since its like a messed up maze! But compared to the mental energy i used making this code, I would have preferred having the multiple proximities ! I was going crazy with this one but I think i understand why the original code wasn’t working now. Really appreciate the example! It is really helpful for another light effect level I’m making that’s just a straight shot cave. I love to torture myself with hard mechanics so having this example will help when we start on the cave so I don’t have to repeat the hours long process I did here. Was losing hope for a bit there and almost had to scrap the light effect.

1 Like

the game you’re making has some really neat mechanics and it would be cool to see where it goes. if you bump into anymore problem/bugs just let me know

1 Like

Thanks so much :blush: This is my first game ever and without the forums here I would be nowhere! When its done I plan on sharing it on here so I can get some input!

2 Likes