The Daily Click ::. Forums ::. Klik Coding Help ::. Creating functions without extensions?
 

Post Reply  Post Oekaki 
 

Posted By Message

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
3rd January, 2011 at 20:57:09 -

Is there any way I can run a function with variables through MMF2 without using extensions like the Func Loop or Fast Function objects? At the moment there doesn't seem to be Flash support for any function-related extensions, so this is one of the main reasons I haven't been able to transfer my games to Flash yet.

I can create normal functions by just using fastloops, but I can't plug variables into them this way. Hmm...

 

Ricky

loves Left For Dead 2

Registered
  28/12/2006
Points
  4175

Has Donated, Thank You!Game of the Week WinnerVIP MemberWii OwnerHero of TimeGOTM Winner! - November 2009I am an April Fool
3rd January, 2011 at 22:58:08 -

The built in fast loop and the for-each both work in flash. Could you use those instead for what you want to do?

 
-

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
4th January, 2011 at 16:25:12 -

I need to be able to plug numbers and strings into the loop.

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
4th January, 2011 at 17:17:48 -

I'm probably just not familiar enough with what you want to do, but why can't you use values and strings in fastloops?

 

  		
  		

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
4th January, 2011 at 18:05:08 -


Originally Posted by OldManClayton
I'm probably just not familiar enough with what you want to do, but why can't you use values and strings in fastloops?

Think like functions in Javascript. He can't pass parameters with the fastloop's name because you can't use the fastloop's name as an expression. He can't parse out parts of a particular fastloop's name, that is.

 
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
4th January, 2011 at 18:22:10 -

So instead, you set the values you need somewhere else and access them during the loop.

 

  		
  		

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
4th January, 2011 at 19:56:44 -

But that doesn't allow an infinite number of different instances of the same function to run at once (he would have to give each fastloop a different name and would have to hard-code a maximum number of different fastloops to support running only that many functions simultaneously).

 
Sandwich Time!Whoo!

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

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
4th January, 2011 at 20:05:40 -

I think I know what you're saying, but I'm not quite sure of the most efficient way to do it. Here's the scenario:

When the player's projectile hits an enemy, I want to plug two variables in: Flag 6, which indicates whether or not the enemy can be damaged, and a string that tells the game what sound effect to play if the hit is successful. Sooo:

Projectile collides with Group.Enemy
- Start loop "Hit Enemy" Flag 6 ("Group.Enemy") times

This is doable enough on its own, because the loop will run 0 times (i.e. not at all) if the enemy is immune to damage. However, unique sound effects will play depending on the projectile, so I need to figure out how to carry over the name of a sound effect so that it plays when the loop runs.

 

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
4th January, 2011 at 20:40:31 -

How many projectiles are there?

Can you not just do this?

Projectile 1 collides with Group.Enemy
+Group.Enemy flag 6 is on
>>Play sound 1

Projectile 2 collides with Group.Enemy
+Group.Enemy flag 6 is on
>>Play sound 2

Or, as long as the projectiles are objects, you can number them in some value. (E.g., Projectile 1's Alterable A is 1, 2's Alterable A is 2, etc.) Then on collision, set a sound counter to the value of the projectile. If the counter is greater than 0, set it to 0 and play the appropriate sound!

I feel like I'm missing a piece of the puzzle here though.

 

  		
  		

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
6th January, 2011 at 10:30:06 -

...*facepalm* For some reason, that never occured to me until now. Thanks.

While I'm here, I might as well ask something else that's unrelated to functions. I'm trying to axe the Direction Calculator from my game as well because it's not compatible with Flash, but I'm currently using its "Rotate Towards Position" feature. How can I do the same thing without using this extension?

Edited by an Administrator

 

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
6th January, 2011 at 11:50:02 -

Use ATan2().

Set Angle to:
Angle + max( min(((( ATan2( YA - YB, XB - XA ) - Angle + 540 ) mod 360 ) - 180 ), TurnRate ), -1 * TurnRate )

That will rotate "A" towards "B", by up to "TurnRate" degrees.

Edited by Sketchy

 
n/a

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
7th January, 2011 at 14:18:52 -

Cool, it works for 360 degree movement. I need it for 32 direction movement, though, so I used this instead:

Set direction:
Dir + max( min(((( (ATan2( YA - YB, XB - XA ) / 11.25) - Dir + 48 ) mod 32 ) - 16 ), TurnRate ), -1 * TurnRate )

Thanks Sketchy!

Edited by an Administrator

 

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th January, 2011 at 14:43:30 -

I was just about to post that
Technically, I think you may need Round() as well - just dividing by 11.25 could be slightly inaccurate in some cases, as MMF may round down, instead of rounding to the nearest direction. I've had that problem before, when converting angles to directions.

Dir + max( min(((( Round(ATan2( YA - YB, XB - XA )/11.25) - Dir + 48 ) mod 32 ) - 16 ), TurnRate ), -1 * TurnRate )

Having said that, I'd still use the 360 degree version, and hold the angle in an alterable value - then set the direction from that. That way, the TurnRate doesn't have to be a whole number.

Edited by Sketchy

 
n/a

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
7th January, 2011 at 15:22:59 -

Ah, sorry about that. I tend to edit my posts really frequently.

That makes sense as well. So I'd stick with the 360 movement, but put it in a value (say, Value D) and just set the object's direction to Value D / 11.25 at all times. Definitely a handy formula to know!


That being said, the only extension left in my game that doesn't have Flash support is the Control X object. I use it because MMF2's Set Key action requires you to press a key in the Event Editor right then and there, and doesn't let you use a value or string.

The only thing I can really think about doing is checking for individual keys one at a time. It's not efficient, but it seems to be the only way to allow the player to customize controls without using the default control menu or an extension.

 

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th January, 2011 at 16:02:09 -

Yeah,
Round( Value D / 11.25 )

For a Flash game, I wouldn't even bother with custom controls. Offer two alternative control schemes (eg. arrow keys vs WASD), but don't worry about total customization.

 
n/a

Strife

Administrator
Der Dairy Crick

Registered
  21/11/2002
Points
  2305

VIP MemberGOTW AWARD! -Astro Dude - part 1 GOTM JULY - 2009 - 3RD PLACE!It's-a me, Mario!Has Donated, Thank You!I donated an open source project
7th January, 2011 at 17:36:07 -

That seems like the best way to go, yeah. Flash games are a lot more "pick up and play" than games you have to install on your PC, so I doubt many people would want to fiddle around with options before playing. In any case, I asked about it on the Clickteam forums in hopes that they can adjust the Player object a bit in the future.

Other than that, problems solved, gentlemen. Thank you muchly!

 
   

Post Reply



 



Advertisement

Worth A Click