Toggle simple switch


#1

I really don’t understand how you make a switch. I have browsed similar questions and tried a multitude of things with no success. There are no tutorials online either. I have tried making a switch for days, almost a week now.

From what I understand you need an extra variable to prevent both evens from being true.


What I am trying to do here is:
Curser on “resource icon” ? [YES]
Button released? [YES]
Trigger the action for this event once ----> Action: clicked on the resource icon = 1

If the variable “onResource”/meaning; The Resource scene = 0
Which it starts at, so [YES] we are currently not on the Resource scene.
Then —> onResource = 1
clickedResource = 0
Change the scene to the Resource scene.

When the player is on the Resource scene and clicks on the resource icon, the game should detect that and direct the player back to the main scene.

If the variable onResource = 1
Which we are
If clickedResource = 0
Then —> we go back to the main scene
and tell the computer that we are not on the Resource scene
aka onResource = 0

Does anyone know how to make a switch, please help me.


#2

guess you have to assign 1 to variable, and multiply it by -1 to keep it changing from -1 to 1.
Use globlal variables. Scene variables resets when you change scenes.


#3

Wait, I am confused. If you put two conditions seperately, both are considered true, no?
So wouldnt that just crash since it cant change to Main and Main_Resouurce at the same time.

Or does this build upon what I had previously but I should remove variable “clickedResource” ?


I tried doing it like I thought you meant. But it didnt work.


#4

the variables differs. -1 and 1.
1 to Main_Resource
-1 to Main
Try my example and see if it works.


#5

it Does work. I tried it and it did.


#6

What value do you assign the global variable onResource?
Do you leave it blank/empty or put a number in?


#7

You have to assign 1.
It has to be 1, because 1 is for Main_Resource.


#8

Yeah it works, thank you very much.
But would this method work if I have multiple of these things?
:blush:
Example; Main_Forest & Main // Main_City & Main… etc

I tried doing it again, same principles but new variables
Example; onForest
But it didn’t work :frowning:


#9

in this example you have only 2 variables: -1 and 1, so you can change 2 scenes.


#10


Shouldn’t this work then?
When I do this, the new one overrides the old one.


#11

I cannot tell you, but instead of multiply by -1 use add1, and use the variable=1 to scene1, variable=2 to scene2, variable=3 to scene3, and so on.


#12

Why are you using 2 objects to go to the same scene?
If so, just add army_icon in the same Actions where resource_icon is.
You have different scenes with equal names?


#13

Ah well I’m trying out things for the UI. And thought this might be the best way. Simulating opening windows, now when my head is a bit more clear now. Maybe I can use layers for the same purpose instead.