The Daily Click ::. Forums ::. Klik Coding Help ::. Help with simple scripting
 

Post Reply  Post Oekaki 
 

Posted By Message

Kirrus



Registered
  15/02/2009
Points
  1
15th February, 2009 at 20:32:13 -

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:

Image

Please help! Thanks!

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
15th February, 2009 at 20:34:32 -

It runs through all of those events even on one runthrough. You'll have to separate them better. No need to use a loop anyway.

 

  		
  		

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
15th February, 2009 at 21:22:46 -

Order of events. You're setting it to 1, and then the next line it reads it as 1, then switches it back to 0.

I'd do it like this
ValSprite = 1 THEN Set Color
ValSprite = 2 THEN Set Other Color

Press + THEN ValSprite = 1
Press - THEN ValSprite = 2

or 0 and 1 in your case.

 
Craps, I'm an old man!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
15th February, 2009 at 22:44:35 -

why not just use a flag and use the "toggle flag" event when space is pressed?

 
n/a

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
15th February, 2009 at 22:47:30 -


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.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
15th February, 2009 at 23:25:02 -

Are you guys seriously into being so efficient that you worry about ONE event's difference?? >_>


 

  		
  		

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
15th February, 2009 at 23:41:31 -

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.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
15th February, 2009 at 23:47:51 -

Whatever floats your boat.

 

  		
  		

nim



Registered
  17/05/2002
Points
  7233
16th February, 2009 at 02:19:52 -


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")

 
//

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
16th February, 2009 at 03:00:54 -


Originally Posted by Jon Lambert

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.

 
n/a

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
16th February, 2009 at 03:19:18 -

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...

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
16th February, 2009 at 04:13:09 -

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

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
16th February, 2009 at 06:28:31 -

"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"

http://en.wikipedia.org/wiki/Boolean_datatype#C.2B.2B

"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?"

say you had a sprite. it had a blue version and a red version. true could represent red and false blue or vice versa.

"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?"

because boolean values take up less memory. if you only need true or false why would you waste memory?

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49567

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
19th February, 2009 at 19:35:38 -

Although PixalThiefs solution is more complicated than it has to be, it really helped me with a problem I'm having, Thanks for that!

 
n/a
   

Post Reply



 



Advertisement

Worth A Click