If Statement Question. Is nesting possible in GameSalad?

acrogodacrogod Member, BASIC Posts: 11

Guys, I'm new to Game Salad, but it definitely is easy to get the hang of and I am enjoying it so far... but I am having trouble understanding how limited or (unlimited) the "if" numeric functions are. Or if I'm making it more complicated than it has to be...

Here's my problem (if I can explain it without confusing you guys or (me anymore than I already am!))

I'm trying to create a card game app similar to Baccarat (same rules for the most part) where basically there are four cards drawn (2) sets of two cards each Banker and Player, and depending on the total value of which two cards the Player gets and the total value of the two cards the Banker gets is whether or not a third card is drawn on either side

For Example:

[Card 3 Banker] [Card 2 Banker][Card 1 Banker] | [Card 1 Player][Card 2 Player] [Card 3 Player]

Four Cards are dealt at first: Card 1,2 Banker and Card 1,2 Player

Card 3 Player is allowed to draw a card depending mostly on the total value of the Player's Two Cards.

Here are the basic rules:

If Player's or Bankers 1st two Cards total 8 or 9 neither side is allowed to draw a third card
The Players side also automatically stands on a Players 1st two card total of 6 or 7
The Bankers side automatically stands on a Bankers 7.

If the Player has a total of 0 through 5 he draws a 3rd card (as long as it doesn't contradict the rules above).

The Banker will only draw a 3rd card if the Players 3rd card is:

If Banker's 1st two cards total:

Banker 3: Player's 3rd card is 0,1,2,3,4,5,6,7,9, (Banker draws 3rd Card) (Banker stands only if Players 3rd card is an 8)
Banker 4: Player's 3rd card is 2-7 (Banker draws 3rd Card)
Banker 5: Player's 3rd card is 4-7 (Banker draws 3rd Card)
Banker 6: Player's 3rd card is 6-7 (Banker draws 3rd Card)

And here's where my issue is:

I have it pretty much working on the Players rules...

The issue is on the Banker's side:

Here's the basic setup of how I've set up my "IF" statements:

Player Side "Draw Card Button"

When "Any" of the following are happening:

if "Player 1st two card total" = 9
if "Player 1st two card total" = 8
if "Bankers 1st two card total" = 9
if "Banker 1st two card total" = 8

do

(left blank)

else

When "all" of the following are happening

Touch is "Pressed"

Change Attribute

set game.3rd card value Player to random 1,52

Bankers Side is basically the same and everything works like the Players side EXCEPT that because there are special rules dependent on the Players THIRD card is where I'm reaching a dead end...

I've tried making separate "if" statements after the "else" statement with no success... it the app still seems to let me draw cards even when I shouldnt be able to.

especially because I'm having to create if statements such as:

if players 1st two cards != 9
if players 1st two cards != 8
if players 1st two cards != 7
if players 1st two cards != 6
if Bankers 1st two cards != 9
if Bankers 1st two cards != 8
if Bankers 1st two cards != 7
if Bankers 1st two cards = 5
if Players 3rd cards = 8

do

(it should be nothing

else

Draw Card

It allows me to draw a card even when the totals say it shouldn't... (I have a display text statement for testing above each card and pairs)

if anyone can help or needs more info, we can discuss privately if need be...

also would it be easier using a table with all the possible combinations? the problem with that is that I don't know the procedures for comparing the card values against every possible combination each time a hand is dealt.

Thank in advance!

acrogod

Best Answer

  • tiger27tiger27 Posts: 127
    Accepted Answer

    @acrogod I created the random(1, 10) to pick a random number value for the card. You can change the number values into any number values you want. The 52 would end up making up random cards since obviously, nothing goes past 14 (or is it 15?) in a deck. To answer the second qusetion, I made quite a blunder! I forgot that Gamesalad doesn't recognize 0-5. Meaning, unfortunately, you will have to write each line individually. (i.e Game.Player1+2=0, Game.Player1+2=1, Game.Player1+2=2, etc.) This sounds like a cool app! Tell me how it goes.

Answers

  • tiger27tiger27 Member Posts: 127

    This is a little complicated, but I'm trying to see what I can do.

  • ArmellineArmelline Member, PRO Posts: 5,366

    What you describe is definitely possible. I'll see if I can find a time to make a demo but getting late here now, and hopefully @tiger27 has it covered :D

  • ArmellineArmelline Member, PRO Posts: 5,366

    @acrogod said:
    If Banker's 1st two cards total:

    Banker 3: Player's 3rd card is 0,1,2,3,4,5,6,7,9, (Banker draws 3rd Card) (Banker stands only if Players 3rd card is an 8)
    Banker 4: Player's 3rd card is 2-7 (Banker draws 3rd Card)
    Banker 5: Player's 3rd card is 4-7 (Banker draws 3rd Card)
    Banker 6: Player's 3rd card is 6-7 (Banker draws 3rd Card)

    So this means that if the banker's two cards total 3, they draw on everything but a player's 8.

    If the banker's two cards total 4, they draw on a player's 2-7.

    If the banker's two cards total 5, they draw on a player's 4-7.

    If the banker's two cards total 6, they draw on a player's 6-7.

    Is this correct?

    Also, how can the player have a total of 0-1 for their first two cards? What are the possible cards to draw?

  • acrogodacrogod Member, BASIC Posts: 11

    Guys, Thanks for the response.

    First, I want to say any help at all is appreciated! And hopefully I didn't make it more complicated than it has to be! Armelline, I should have also explained that in Baccarat, card values are A=1, 2-9 are equal to their face value and face cards are equal 0. if you add two or three cards together and they equal more than 10 or 20, you drop the tens value.

    For Example:

    8+J+8 would equal 6
    A+7+5 would equal 3

    and in the game (following the rules of Baccarat) people bet on either the Banker or the Player to win by having the the higher total score after the cards are drawn.

    For Example:

    a Baccarat Playing Field would be set up similar to this:

    http://www.fastodds.com/images/games/baccarat_gold_650x488.jpg

    In the image i've linked to, the Player wins 2-0 after the cards are drawn .

    I'm just wondering if I've got to make a rule for every possible combination, in a specific order, and multiple copies of the rule.

    Thanks again guys!

  • acrogodacrogod Member, BASIC Posts: 11

    Also, as a side note, I'm technically not trying to totally recreate the game, but more of a teaching tool. for example, if you try to draw the 3rd card for either side and it goes against what's allowed by the rules of drawing the cards, it'll notify you that it's not allowed.

    like I said before, I have the Player's side rules almost done because they are pretty much a static set of rules. The Banker's side rules are a pain in the butt, due to the fact that it depends on both the Banker's 1st two card total AND the Player's 3rd card as to whether the Banker draws another one.

    So I'm not sure if I should do this (for each card):

    I "All" are Happening:

    If P1P2Total = A1
    If P1P2Total = A2
    If P1P2Total = A3
    If P1P2Total != B1
    If P1P2Total != B2
    If P1P2Total != B3
    If B1B2Total !=C1
    If B1B2Total !=C2
    If B1B2Total !=C3
    If B1B2Total =D
    If P3rdCard=E

    do

    draw B3rdCard

    else

    do nothing (or display notification saying card can not be drawn)

    The problem with all the combinations of all the card totals and cards drawn, it can get messy trying to cover all the card totals and card combinations possible.

    i have created a table that it pulls from with the card values and images (which makes shuffling easy)

    In the table, the 10, J, Q, K values are all "0" so it makes it easier in calculating total card values (except for when adding 2 or 3 cards together which I have to drop the 10's value)

    UGH!

    Again, Thanks guys!

  • tiger27tiger27 Member Posts: 127
    edited July 2015

    Hey I did it! I can't upload the project, so I'll give you the code here. But, first you need a table, a single actor and 8 attributes titled:

    Player Gets 3rd (boolean)
    Banker Gets 3rd (boolean)
    Player Stand (boolean)
    Banker Stand (boolean)
    Player 1+2 (integer)
    Banker 1+2 (integer)
    Players 3rd= (integer)
    Players 3rd= (integer)

    The table's columns/rows should be:
    Card 1 Card 2 Card 3
    Player 0 0 0

    Banker 0 0 0


    Here's the code (In the one actor):

        Change table value
        Table 1
        Row 1
        Column 1         random(1, 10)
        Column 2         random(1, 10)
       ____________________________________
        Change Table Value
        Table 1
        Row 2
        Column 1        random(1, 10)
        Column 2        random(1, 10)
        ______________________________
        Change attribute 
        Game.Player1+2 to tableCellValue(Game.Table1, 1, 1)+tableCellValue(Game.Table1, 1, 2)
       ______________________________________________________________________________
        Change Attribute
        Game.Banke1+2 to tableCellValue(Game.Table1, 2, 1)+tableCellValue(Game.Table1, 2, 2)
        ___________________________________________________________________
        Rule
        If ANY or the following are happening
        Game.Player1+2=8-9
        Game.Banker1+2=8-9
    
        Change attribute
        Game.PlayerStand to true
        Game.BankerStand to true
      _____________________________
        Rule
        If ANY of the following are happening
        Game.Player1+2= 6-7
    
        Change attribute
        Game.PlayerStand to true
     ___________________________________
        Rule
        If ANY of the following are happening
        Game.Banker1+2=7
        Game.Players 3rd==8
    
        Change attribute
        Game.BankerStand to true
        __________________________________
        Rule
        If ALL of the following are happening
        Game.Player1+2=0-5
        Game.PlayerStand is false
    
        Change attribute Game.PlayerGets3rd to true
       _______________________________________________
        Rule
        When ALL of the following are happening
        Game.PlayerGets3rd is true
    
        Change table value
        Table 1
        Row 1
        Column 3    Random(1, 10)
    
        After 0.001 seconds
        Change attribute Game.Players3rdCard to tableCellValue(Game.Table1, 1, 3)
      ________________________________________________________________________
        Rule
         if ANY of the following are happening
        Game.Players3rd=1-7
        Game.Players3rd=9
    
        Change attribute Game.BankerGets3rd to true
        __________________________________________
        Rule
        When ANY of the following are happening
        Game.BankerGets3rd is true
    
        Change table value
        Table 1
        Row 2
        Column 3    Random(1, 10)
    
        After 0.001 seconds
        Change attribute Game.Players3rdCard to tableCellValue(Game.Table1, 2, 3)
    

    Hope that works! Tell me if it does not.

  • acrogodacrogod Member, BASIC Posts: 11

    Tiger27, Thanks so much! I've spent the better part of the morning creating the actor, table and entering in the code. The only thing I have left to do is wrap my brain around what each rule does specifically... I can interpret most of it, but trying to see how I can fit it into what I already have is a bit tricky... only because I'm new at this. But it does make more sense than how I had it set up.

    There are a few additional rules I have to set up in there such as the 667, 547, 427 rule... (see above) unless I'm missing where it is in the code you've provided...

    I have a few questions to clarify:

    Question 1:

    Are the random functions (1-10) just simulating the card shuffling for each card?

    I only ask, because the way I have it set up is a table that basically goes:

    4 columns:

    Card Name (ex: Ace of Clubs)
    Card Value (0-9 repeatedly)
    Image Name (each playing card image name)
    Row Number (1-54 to include the card back & card blank image (this column's probably redundant))

    54 rows:

    The way I shuffle is to pull a random number from 1-52 and have the change attribute show that image from the Column 4.

    tableCellValue(CardTable,Random(1,52),4)

    It works great since a normal Baccarat shoe is 8 decks, I don't have to worry about using up all 52 cards.

    Question 2:

    When you have a Rule such as:
    <---- Rule If ALL of the following are happening Game.Player1+2=0-5 Game.PlayerStand is false ---->

    Do I have to create a line for each 0 thru 5

    ex:

    Game.Player1+2=0
    Game.Player1+2=1
    Game.Player1+2=2
    

    or does Game Salad recognize the syntax:

    Game.Player1+2=0-5
    

    Anyway, Thanks for the work so far... and I apologize for any questions that sound like TOO much of a novice!

    acrogod

  • tiger27tiger27 Member Posts: 127

    Glad I could help!

Sign In or Register to comment.