playMaker

Author Topic: How can I do math on variables?  (Read 2277 times)

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
How can I do math on variables?
« on: April 06, 2013, 06:33:06 PM »
For example, I want  100 sprites placing in a nice line. How do I set an object to be positioned at a variable + or - an amount or with any math for that matter..eg:

HalfTheEggs=AllTheEggs/2
BigMoveAMount=NormalMoveAmount*5

..etc..

Basically I can see how to input variables but do I need to create new variables for every part of the equation?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How can I do math on variables?
« Reply #1 on: April 06, 2013, 06:37:37 PM »
You need to use a loop. E.g., loop through a state that places a new sprite adding an offset to a spawnPosition variable each time.

Checkout PlayMakerSamples\TestLab\Spawning\SpawnGrid for an example. That sample uses a delay between each spawn, but you can set that to 0 to spawn all the objects in a single frame.

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: How can I do math on variables?
« Reply #2 on: April 06, 2013, 06:58:12 PM »
Okay, but is there a way to use variables with math in an action? ..or do I have to create a new variable for each of the following instances?

Eg
ACTION:GUI Horizontal Slider 1 PARAM:Left Value VAR: Slider Position
ACTION:GUI Horizontal Slider 2 PARAM:Left Value VAR: Slider Position * 2
ACTION:GUI Horizontal Slider 3 PARAM:Left Value VAR: Slider Position * 3

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How can I do math on variables?
« Reply #3 on: May 14, 2013, 04:16:49 AM »
Hi

You might have to have one variable for each yes, especially if you want to use them differently in the end. IF it is just to reach a final variable, then you can reuse variable until you reach the final value.

bye,

 Jean