playMaker

Author Topic: Working with variables and conditions  (Read 1611 times)

matthew38940

  • Playmaker Newbie
  • *
  • Posts: 2
Working with variables and conditions
« on: August 05, 2014, 10:34:18 AM »
I am pretty new to Playmaker, but I have watched and read a lot in order to try and get familiar with it all.  My biggest question and possibly concern though has to do with conditions and variables.  I am trying to figure out the best way in playmaker to make things happen based on a variable. 

For instance, if I am working on basic card game and have 52 cards in the deck.  I want to give the player one random card out of the 52.  I figured out the random part easily and such, but the part I need help with is determining which of the cards it is.  I set it up to make a variable a random number (1 through 52) and got that working.  But I could not find an efficient way to then take that variable and depending on which number it is give it a card name.

Something like this equation (just an example I am by no means a coder of any language)
if (Card = 1)
{ CardinHand = AceOfHearts }
else if (Card = 2)
{CardinHand = KingOfHearts}
etc...

So basically is there way to make it easily read what number the random card is and then use that to change another variable to represent that card (and then later use that for various purposes)

So far the only way I have figured out to do so was to make a State that assigns the random number and then made 52 events based on each of the possible numbers.  And then make 52 states (one for each event) that then assigns which card it is.  It felt like a lot of busy work, for something that I feel other things handle very easily so I am guessing I am completely just missing something obvious.

I hope this makes sense and that someone can let me know if there is any easier methods.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Working with variables and conditions
« Reply #1 on: August 05, 2014, 01:20:22 PM »
If you're working with the four suits I'd probably break that up first.

So, keep the "each card has an identifier" approach (so, say, the ace of hearts is 1 whereas the ace of diamonds is 14) and if you take the random variable you can do a test to see if it's below 13, below 26 and below 39 to determine the suit... Assign that "what suit is it" to an int value which would be from 0-3... Take that random number, subtract 13*i (unless the initial test is saying that the suit is "0" in which case you simply skip the multiplication bits to prevent a div-by-0 error) where i is the suit identifier and stash this new int in a working variable (eg. "i") and then run it through an int-switch to determine what value card it is.

Here's a test screenshot... I think in the suit-sorting system that the action sequence option should be on just to be sure that each int compare is running in sequential order so as to prevent any accidental mis-sorting...

So, this would take the random int you set up and turn it into the value of the face card and have an int that determines the suit of the card itself... So, you have a random value being made of... "23" it will then give you a suit of 1 (clubs) and a ID of "10" so it's the ten of clubs. (in this example I'm assuming that the ace is 1... some people might want to make the ace the higher card so tailor that to your own purposes.)

EDIT: in this example I over-wrote the initial "card ID" int value... If you need/want to keep that value unique you could make a new int value of "Card face value" or something like that where you assign it's face value... So you'd have "Random card", "Suit" and "Face Value" integer values being created for this kind of thing.
« Last Edit: August 05, 2014, 01:31:00 PM by Red »

matthew38940

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Working with variables and conditions
« Reply #2 on: August 05, 2014, 05:02:22 PM »
I am not where I can try out your method right now, but that does look like a much quicker (and far less repetitive clicking) way of doing the task.  Thanks for the in-depth reply!