Creating a toggle function with Active System Box
Hi,
I'm trying to create an active system box which when clicked changes to a different colour, and when clicked again changes back. I also need to update an INI file on each click.
For some reason, I can only get it to work for the first click- but it won't return. Have I missed something obvious?
The sequence goes:
1) Start of Frame
Load toggle state from INI (on or off) save to [Box] internal value A
2) When user clicks with left button on [Box]
+ [Box] Internal value A = 0
Toggle to ON (change colour of [Box]
and update INI
3) When user clicks with left button on [Box]
+ [Box] Internal value A = 1
Toggle to OFF (change colour of [Box]
and update INI
That should work right? I've tried adding Run Once per Loop and I've tried using counters instead of internal values.
Let me know if an example file would be useful and I'll try to upload it.
I'm using MMF2 Standard, build 242.
Thanks in Advance,
toast0r
Re: Creating a toggle function with Active System Box
That code won't work. It'll see that it is off, so turn it on - then see that it is on, so turn it off.
Instead, make it so if you click the button then it toggles a flag using the toggle facility. Then in the next two events make it check whether or not that flag is on and act accordingly.
Re: Creating a toggle function with Active System Box
Thanks Joshtek - your solution works perfectly - I knew it would be something obvious!
Out of interest though, why is it that the other code didn't work? Surely if the button in only being clicked a single time it should never get as far as the third line of code for turning it back (if you see what I mean).
Thanks for the help.
Re: Creating a toggle function with Active System
MMF runs all events that begin with "user clicks on ..." when you click on something. It doesn't matter if one line runs properly (ie passes all the conditions) it will run the others anyway.
So in your case clicking on the box will make it always run both lines 2 and 3. It also runs the lines one after the other, not both at once, so that's why changing the box's value in line two makes line 3 succeed.
Like this:
User clicks on a box and internal value is 0:
2) When user clicks with left button on [Box]
+ [Box] Internal value A = 0
Set internal value to 1
So the internal value is now 1. Then it runs this line, because it starts with "user clicks on" as well:
3) When user clicks with left button on [Box]
+ [Box] Internal value A = 1
Set internal value to 0
So the internal value is now 0 again.
Re: Creating a toggle function with Active System
That makes much more sense - thanks for clearing that up.
Slightly off topic I guess but is there a way to make MMF wait for a given time from passing a condition to carrying out the required action?
ie.
1) [Active Object 1] colides with [Active Object 2]
Wait 10 seconds THEN destroy [Active Object 2]
or would I have to create a timer 'every 1 second add 1' or similar?
Thanks for all the help, much appreciated.
Re: Creating a toggle function with Active System
Quote:
Originally Posted by toast0r
or would I have to create a timer 'every 1 second add 1' or similar?
Yes, that (or similar).
Re: Creating a toggle function with Active System