Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: weilies on February 19, 2015, 07:13:12 PM

Title: How to compare multiple string?
Post by: weilies on February 19, 2015, 07:13:12 PM
I know there is a string compare action in PM.
But is there a more convenience way to compare multiple variable in one time?
E.g. A rock paper scissor game, I would like to compare player 1 throw ROCK and player 2 throw PAPER?

If using string switch or string compare action, i will need many states to achieve

Quote
// PlayerMode 1 (Single Player), 2 (2 Players)
If PlayerMode = 1 AND Player1Gesture = 'Rock' AND PlayerPCGesture = 'Scissor' Then
....
Title: Re: How to compare multiple string?
Post by: weilies on February 19, 2015, 08:06:23 PM
kindly checkout the attached document.
It's the scenario i wanna cater. but i would think it's a nightmare if i need one state to cater for a cell.

PM gurus please guide.

Thanks
Title: Re: How to compare multiple string?
Post by: Lane on February 19, 2015, 08:47:40 PM
Hmm. I think you overcomplicate the problem.

There are always two players regardless of whether it is an AI or not, so half of those conditions can be voided with some adjustments to your structure.

Where a draw is concerned, if Hand1 = Hand2 then draw, that is the only condition for a draw, you can use a basic string compare for that. If the gestures are the same then it is a draw.

For the rest of the compares it its slightly more but still not that bad. Its a matter of stepping through a few states based on the plays. You can actually sort of do IF statements with states in a way by making each state the IF, using compare actions, and only firing the TRUE event. This will flow down the action stack, process each compare and fire an event when one is True. So in effect you could first say String Compare Gesture 1 to Paper, then Rock, Then Scissor and get into the next state where you compare against the strings that it would win or fail against and see if the other gesture matches those, then firing appropriate events from there.

Hope that gives you some fresh thoughts on the approach.