I'm trying to do some simple practice scripting in Multimedia Fusion 2, yet I'm stuck on what I think should be a simple problem. I want to press a button and have my character toggle between two colors. So I set a variable to switch between 0 & 1. Pressing space would switch the number back and forth. Yet, when I script it, it only toggles to 1 and doesn't go back to 0. I set up an "and" statement, made a loop that changes the numbers depending if it's at 1 or 0. Here's a picture of my event editor:
Yes. That one event is the difference between 9000 and 9001 events, and no one wants over 9000 events.
Memes aside, I find it best to minimize the amount of events you use whenever you can. Unnecessary events pile up fast and it's a lot harder to clear them out 50 at a time as opposed to 1 at a time.
Originally Posted by Cecil why not just use a flag and use the "toggle flag" event when space is pressed?
Yea, definitely use the toggle flag action. Also, it's useful to know that a flag is an integer and can be used in calculations. Sooo, if you're feeling all efficient and stuff, you could say:
User Presses [key]
> Toggle Value("Flag,0")
> Change Direction of Active("Player") to Value("Flag,0")
Originally Posted by Cecil why not just use a flag and use the "toggle flag" event when space is pressed?
I was going to say that earlier, but wouldn't that require three events? Whereas using Value=x + Press fire 3 would only require two events.
-upon pressing 'space'
>toggle flag
>change color of thingy according to value of flag.
thats only one event if you want to get even more efficient. although if youre planning on having more than just 2 colors you will eventually need to keep track. also needing more than just a few events.
Wait, so how does the value of a flag work then? Is it just zero and one, or can it be other numbers? I'm not sure what the point would be in changing from 0,0,0 to 1,0,0. If you had to set it as other values then how would toggling work? I know you can change the default, but I still don't get it. If flags are as dynamic as alterable values, then why have both? Maybe I can learn something...
Well, I'm going to spell out the problem with the original code.
When the game runs, it reads through each event of the loop once at a time, fully, before going on to the next loop. So when you press FIRE 3, first it reads that your VALUE = 1, and changes it to VALUE = 0. Thats the EVENT #6. But then, it hits EVENT #7. Because the VALUE = 0 now, *that* event is now true, and it changes it back to VALUE = 1.
So each time you press FIRE 3, both of those events are activating, the top one first, then the bottom one. If you switched the order of them, you would find that the value would always be 0 instead of 1. Does that make sense?
So if you wanted to keep your code just like it is, using that loop and switch format, what you need to do is make sure the loop de-activates itself after changing the color. So what you need to do is this:
+On Loop "Change"
+COLOR = 1
=Set COLOR = 0
=Stop Loop "Change"
=Close Group ("Color Change Sub-loop")
Now heres the neat part; move all of your "On Loop" code into an event group called "Color Change Sub-loop". Whenever you start the loop, like in that fire 3 command, do an "Open Group" event BEFORE the "Start Loop" command. This way, when the loop runs, it will close the group as soon as its done, so it can't read any further code.
The trick here is that using "Stop Loop" in MMF2 does not actually break a loop. It just tells the loop to stop after finishing its current cycle. So it will run all the way down the code before it stops. So if you had a loop running 30 times, you could stop it after the 5th, but you couldn't *interrupt* the 5th run. Does that make sense? But when the further code for that loop is all inside of an event group, when the group is closed, the system will ignore it. So as soon as you close the group, the loop is broken.
This might be more complicated then the other peoples solutions, but I hope you can learn a programming trick or two out of it
"Wait, so how does the value of a flag work then?"
flags are basically boolean values which is an integer data type. it can either be true or false. 0(false) or non-zero(true). it is only one digit (1 bit).
"can it be other numbers?"
no it only has 2 or 3 values.
true, false, and sometimes "unknown"