Displaying Random Table Cell Values

DocJDocJ Member Posts: 66

Hi guys,
I can't tell you what a feeling it was thinking I had something figured out on my own.....but then reality set in :/

I have a 2 column table that is having one of the rows chosen at random (titled self.Row).

It is followed by a Display Text: TableCellValue(game.TB_Red, self.Row,1)

I am trying to accomplish two things with this, and as I said, I thought I had figured out how to do this.

I would like to be able to take the value from the second column of the self.Row and use it a base number to add to 5 other similar table outcomes, and then display the final result.

At first I had a Display Text: 0+ TableCellValue(game.TB_Red, self.Row, 2)
That seemed to work.....it displayed the value of the 2nd column as hoped. Unfortunately it did this right in the Actor, right on top of the value from column 1

So I figured instead of inputting the TableCellValue expression each time, I would give it a name, which would also help me with my second problem, being able to display it somewhere else on screen.

What I thought I had was this:I made an Integer attribute in the Red Actor, titled Red Score and set it to 0.
Change Attribute
Set: self.Red Score to: 0+ TableCellValue(game.TB_Red, self.Row,2)

I was then going to have a Game attribute called Score which would add the 5 subsequent values to form one total (i.e. Red Score + Blue Score + etc...).  

That's when it didn't work anymore.

Did I miss something?

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited April 2015

    If to worked before, why not use the display text offer so you can change and x and y values? This means you can have more than one display text behavior in each actor. Before, having for than one would mean that text would overlap.

    Edit: silly me - I just saw that you posted in the PC section. I'm on mobile now, but once u get back to a mac or PC I'll write something more in depth.

  • DocJDocJ Member Posts: 66
    edited April 2015

    @Braydon_SFX I'm glad you're going to write something more in depth later, because I didn't understand what you wrote :)

    Scratch that.....I understand what you were referring to me not being able to do because of the Relative To positions available on the Mac, not the PC

    I look forward to your response later though

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If I understand correctly, you're wanting to display two values: the column 1 value and the sum of several column 2 values. What I don't know is where you want to display these. Do you want them next to each other like this:

    14 25
    Which would be done with TableCellValue(game.TB_Red, self.Row,1).." "..game.sum

    Or stacked like this:

    14
    25
    Which would be done with TableCellValue(game.TB_Red, self.Row,1).."\n"..game.sum

    Or something else?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DocJDocJ Member Posts: 66

    @tatiang Hi. The only reason I was trying to display the 2nd column to begin with, was to see if I was getting the value I wanted. I don't actually need to display the 2nd column value until I add the total of 5 2nd column table values to put on a scorecard, which will be located somewhere else on the screen.
    I figured if I could name the 2nd column value for the Red Dice, Red Score, then I could just add Red Score + Blue Score + Yellow Score, etc...
    I would display that total score, then have each one reset for the next round. Kind of like Yahtzee does.
    Do you think my problem was where I named my Red Score attribute? (Actor, Scene, or Game)? I think once I figure out where to give it the proper attribute, I'll be able to display it with a Display Text

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    So is the main problem that you want to avoid stringing together a bunch of tableCellValue() functions in the Display Text behavior? Otherwise, just string them together with addition symbols between them.

    As for the type of Red Score attribute, it shouldn't really matter but if there's ever a doubt about an attribute type, make it a game attribute.

    Sorry if I'm still not understanding!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DocJDocJ Member Posts: 66

    Exactly. Not that I don't want to string all those TableCellValues together, I just thought there was an easier way.
    I will go back to the drawing board and try again with the Red Score attribute. I'll post back later with an update. As always, thanks for your input. Much appreciated!

  • DocJDocJ Member Posts: 66
    edited April 2015

    OK, experimenting a bit more, I now have part of my problem solved.......

    I made a Constrain Attribute called self.RedScore
    constrained it to: 0+TableCellValue(TB_Red, self.Row,2)

    Then I used a Display Text: self.RedScore
    That works.

    Now I will figure out a way to take that attribute and add it to 4 other separate attributes and display it.
    Maybe I'm doing this wrong, I'll do more research.

    I made a game.TotalScore attribute. What seems to make sense to me would be to add the sum of self.RedScore + self.BlueScore + self.YellowScore, etc.....

    Here's where my logic hits a brick wall. When I try to make a Change Atrribute:
    set: game.TotalScore to: self.RedScore + self.BlueScore, etc.....
    There is no access to the self attributes in the expression editor

    I must be missing something....something probably simple too

  • DocJDocJ Member Posts: 66

    Update: Found out what I was doing wrong.

    Picture a Yahtzee-style game with 5 dice.
    Each dice was to give a random "phrase" with a numerical value (in column 2 of the 5 tables)
    I was trying to give each dice its own attribute: self.Red_Score, self.Blue_Score, etc...
    I was then trying to make a game attribute: game.Total Score which would be the sum of self.Red_Score + self.Blue_Score....until all 5 dice were added together.

    Unfortunately, I kept getting lost in my inability to make an attribute like that.
    Every time I brought up the expression editor, there was no Red Dice, Blue Dice, etc listed.
    I finally realized that I had to make my self.Red_Score, self.Blue_Score, etc......game attributes, not self attributes.
    Now my game.TotalScore is the sum of game.Red_Score + game.Blue_Score, etc....

    I hope this helps somebody in the future who is trying to give each actor their own score

    My thanks to @tatiang and @Braydon_SFX for their input

Sign In or Register to comment.