Author Topic: Variable/Conditional Events (V.4)  (Read 61484 times)

Is there any way to make it remove/add the whole variable?

Example:
OnActivate>Player>AddVariable   Money   -*
And that would remove all of their money?


SetVariable to 0? xD
How would I add a whole variable though? See
SEEEE

could somone post a save of a small  build demonstrating these events i tried to make them work but  each time  i try then when i  make a brick display variable it just says is. Please somone post a save demonstrating these events

sorry for double posting but anyone?

onActivate>Self>ifVariable>Money equals 1
VariableTrue>Player>AddVariable>Money -1
VariableTrue>Player>Setvariable>Test 1
OnActivate>Self>ifvariable>Test equals 1
VariableTrue>Client><Centerprint Hello

That should work :/
However, it doesnt
When i click, it plays all of the events

onActivate>Self>ifVariable>Money equals 1
VariableTrue>Player>AddVariable>Money -1
VariableTrue>Player>Setvariable>Test 1
OnActivate>Self>ifvariable>Test equals 1
VariableTrue>Client><Centerprint Hello

That should work :/
However, it doesnt
When i click, it plays all of the events

same :(

onActivate>Self>ifVariable>Money equals 1
VariableTrue>Player>AddVariable>Money -1
VariableTrue>Player>Setvariable>Test 1
OnActivate>Self>ifvariable>Test equals 1
VariableTrue>Client><Centerprint Hello

That should work :/
However, it doesnt
When i click, it plays all of the events

You need to use this.

You need to use this.
That effects other players, rather than just the one that clicks it

If anyone needs help and can host a sever i will be glad to come and teach you :cookieMonster:

onActivate>Self>ifVariable>Money equals 1
VariableTrue>Player>AddVariable>Money -1
VariableTrue>Player>Setvariable>Test 1
OnActivate>Self>ifvariable>Test equals 1
VariableTrue>Client><Centerprint Hello

That should work :/
However, it doesnt
When i click, it plays all of the events

Tutorial - Multiple Variable Checks In One Brick
Syntax: (Delay) Input Target Output (Parameters)

I've noticed this question has been asked a lot lately, and thought I'd write up a quick guide on it. It's pretty simple, but often overlooked.

When one thinks about it, using multiple variable checks is like looping through each variable check and then proceeding to the next. In events, it works in a similar fashion. If you have a decent knowledge of events, the word "loop" should've just alerted you of relays. So, to start the loop, we need to use this event:

Code: [Select]
(33) onActivate Self FireRelay
(0) onActivate Self setEventEnabled ([var check 1 events] Enabled)

Note that you can change onActivate to however you want to initiate the multiple variable checks. It could be onPlayerTouch, onRespawn, or anything else. Just note that if you want to trigger the multiple variable checks with onRelay you do NOT need the first event. Also, since you do not know how many events you have in your first variable check, leave that blank for now, but remember to come back and add to it later. Now, to continue the loop, unlike most would think, we need to use these:

Code: [Select]
(33) VariableTrue Self FireRelay
(33) VariableFalse Self FireRelay

You can't use onRelay Self FireRelay because it will continue looping even after the last variable check has been performed. That is why we only continue the loop if a variable check fails or passes. Next we will need to create our first variable check, and they will be triggered by an onRelay. Add VariableTrue and VariableFalse events as necessary. Here is an example:

Code: [Select]
(0) onRelay Self ifVariable (Player Money GreaterEquals 10)
(0) VariableTrue Player AddVariable (Money -10)
(0) VariableTrue Player AddVariable (Logs 1)
(0) VariableTrue Client Centerprint (You have bought a log.)
(0) VariableFalse Client Centerprint (You do not have enough money.)

So basically, I just checked if they had enough money to buy a log, and if so, gave them one. If not, I displayed an error message. Now for the fun part: Switching to the next loop. To put it simply, we toggle the events down the line.

Code: [Select]
(0) VariableTrue Self ToggleEventEnabled ([var check 1 events] [var check 2 events])
(0) VariableFalse Self ToggleEventEnabled ([var check 1 events] [var check 2 events])

For the events you toggle, put in the event numbers of your first variable check. You will also need to add the event numbers of your second variable check, but if you don't know how many events you'll have in your second variable check, just wait until you make it before you add those numbers in. If you want the variable check to NOT proceed to the next one, simply don't use toggle events on either VariableTrue or VariableFalse, whichever one applies to you. Instead, use the code for ending the loop that you can find at the bottom of the guide. Here's an example of the next variable check:

Code: [Select]
(0) onRelay Self ifVariable (Player Logs Equals 10)
(0) VariableTrue Client Centerprint (You have bought your tenth log!)

So as you can see, I just simply put a notification that you have bought your tenth log when you do so. Even though I don't have any VariableFalse events, I still need to remember to add these two events after it:

Code: [Select]
(0) VariableTrue Self ToggleEventEnabled ([var check 2 events] [var check 3 events])
(0) VariableFalse Self ToggleEventEnabled ([var check 2 events] [var check 3 events])

Note that the ToggleEvents are included in each variable check. This means that when you are putting in the event numbers for what to toggle, include the event numbers of the togglers themselves. If you just checked for the last variable check you want to do, put this instead:

Code: [Select]
(0) VariableTrue Self setEventEnabled ([var check 2 events] Disabled)
(0) VariableFalse Self setEventEnabled ([var check 2 events] Disabled)

How the process for people who visualize things well:

1) Initiates loop, and turns on the first variable check
2) Checks the first variable check
3) Turns off the first variable check, turns on the second variable check
4) Proceeds in the loop
5) Checks the second variable check
6) Turns off the second variable check, turns on the third variable check
7) Proceeds in the loop

And so on and so on.

Well, that's all there is to it. Really, it's just like putting together a big puzzle. I believe I explained it thoroughly enough and provided decent examples, but I have a tendency to ramble without realizing it. So, if you have any further questions, feel free to just PM me so I can clear things up for you.

im new to variables can they give players "gold" with events on bricks and deduct the "gold" by clicking market bricks like if theres a Y and N[yes and no] and you click a yes brick it takes away a certain amount of "gold" and give you an item

I heard v.4 is going to have saving variables. Can anyone give me some info on how that is coming along?

I heard v.4 is going to have saving variables. Can anyone give me some info on how that is coming along?
I'm not sure, you may need to talk to Chrono, as he is incharge of doing this. They may not make it into v4, but they will definitely be in v5.