[Solved] Trigger only certain attributes randomly using tables

ApprowApprow Member Posts: 703
edited June 2015 in Working with GS (Mac)

I'm sure what I want to do is achievable, but I'm not sure what the best and most efficient way is.

For example:
I have 15 different power ups which can be unlocked when the player buys them. All their properties are saved different table cells. Okay, I get how this should work when all of them can appear randomly in the game. But lets say power up 1,2,4,7,13 and 15 are unlocked, how can I make only them appear randomly without setting up a ton of rules?

Also, is there an equation which can make the better power ups appear less often compared to the lower ones, when they are ranked from 1 to 15. So 1 will be very common, and 15 will be very rare.

Thanks a lot if you can help:)

Comments

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

    If you have a separate actor for each power up, you can just enable/show that actor based on the table cell value for that row.

    For varied random value generation, try a table:
    1
    1
    1
    1
    1
    2
    2
    2
    2
    3
    3
    3
    4
    4
    etc.

    Then pick a random value by changing game.randomNumber to tableCellValue(tableName,random(1,tableRowCount(tableName)),1).

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

  • ApprowApprow Member Posts: 703

    @tatiang said:
    If you have a separate actor for each power up, you can just enable/show that actor based on the table cell value for that row.

    Thanks for the reply. I'm not really sure what your solution is by using separate actors for each power up. I want to know "how to trigger" those separate actors randomly, but only the ones who are bought by the player. And I cant use separate actors by the way because everything gets recycled in the game, otherwise it gets a little nuts haha. I just need the numbers.

    For varied random value generation, try a table:
    1
    1
    1
    1
    1
    2
    2
    2
    2
    3
    3
    3
    4
    4
    etc.

    Then pick a random value by changing game.randomNumber to tableCellValue(tableName,random(1,tableRowCount(tableName)),1).

    I already knew this method, but how can I relate this regarding to my first question. I thought there might be a mathematical solution for this, because the number of the unlocked power ups can be variable (1,2,4,7,13 and 15, the other ones simply cant be triggered). All the 15 power ups have their own column, and every power up has some property's stored in the rows below them, so I want to use only one table for all the power ups, its properties, and its rareness.

    Now I'm starting to think I'm asking to much, or something insane. But I have seen things on the forums I didn't even knew were possible with math. Or I might use some different logic.

    If my explanation wasn't clear enough, please let me know. Thanks for helping me @tatiang !

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

    No, it wasn't clear enough. You really need to provide a picture (verbally perhaps but better if it's an actual image) of how this will all work. I still have no idea if there are a bunch of power up "slots" in the game or a single character with a power up over its head or a spinning wheel of power ups... it matters when you're asking how to set this all up.

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

  • ApprowApprow Member Posts: 703

    @tatiang I thought so, excuse me. I made a little demo project to show what I mean. by the way it doesn't matter if the power up is a hat, a helicopter or a giant flower. I just need the randomly generated numbers.

    Click the big white box to randomly change the table rows which represent to power ups.
    On the right you see its status, 0=locked 1=unlocked. To unlock the power ups you can press the buttons below, Button 1 unlocks power up 1, button 2 unlocks power up 2, etc. I guess it makes sense when you see it. What I want to archive, is that the power ups with a locked status, are not randomly generated with the unlocked ones. So in short, the game needs to search through the table to find the unlocked power ups, and choose randomly out all the unlocked ones he found.

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

    No, I realize the image of the powerups isn't important. I was referring mainly to the number of powerups on screen. If you have a single actor representing multiple powerups, it's going to be hard to do what you have in mind. If you had an actor (i.e. instance) for each one, it's quite easy.

    I'll take a look at the demo...

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

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

    I'm still not quite getting the idea. When you click on the top actor, it chooses a random value from 1 to 8. Then, if you click on one of the power up actors, it allows you to buy it if its value matches the random number. So far so good.

    But... you also want the power up actors to appear randomly based on probabilities if I'm understanding correctly. So each time a new random number is generated, it should display one or more already unlocked power up actors? Or do you want all of the unlocked power ups to appear but in random order on the screen? You may have to Loop Over Table to do this.

    Also, you keep using the word "archive." I think you mean "achieve." :)

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

  • ApprowApprow Member Posts: 703

    @tatiang Haha thanks for the correction, english is not my native language.

    I'm still not quite getting the idea. When you click on the top actor, it chooses a random value from 1 to 8. Then, if you click on one of the power up actors, it allows you to buy it if its value matches the random number. So far so good.

    Yep, but the buy button doesn't need to match with the power up, it doesnt really matter anyway for now haha.

    But... you also want the power up actors to appear randomly based on probabilities if I'm understanding correctly. So each time a new random number is generated, it should display one or more already unlocked power up actors? Or do you want all of the unlocked power ups to appear but in random order on the screen? You may have to Loop Over Table to do this.

    Yes and no, but I do think you understand what i'm saying. You can forget about its properties for now, I don't know why I mentioned that because it's not relevant to my question I suppose xD

    Lets take a scenario. The player bought power up 1,2,5 an 6, and the hero overlaps/or collides with a question mark actor. This question mark actor will scroll through all the unlocked power ups, and chooses one random unlocked power up, number 5. now the hero gets a special ability thats related to number 5. This question mark can ONLY choose out of the unlocked power ups. Taking random numbers is not an issue when the list is chronologic, but thats is not the case here.

    Its kind of a pain in the ass to explain this, but it comes down to table search I guess, which I suck at -.-

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

    Lets take a scenario. The player bought power up 1,2,5 an 6, and the hero overlaps/or collides with a question mark actor. This question mark actor will scroll through all the unlocked power ups, and chooses one random unlocked power up, number 5. now the hero gets a special ability thats related to number 5. This question mark can ONLY choose out of the unlocked power ups.

    This makes so much more sense now! Okay, I get it. I'll see if I can set up a demo for you, at least for part of this.

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

  • ApprowApprow Member Posts: 703

    Haha great! I'm stuck at this thing for a while now, thats why I got a bit crazy with the questions. Thanks for the help, really appreciate it!

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

    Here's the demo. It does not use any probability so each power up has the same chance of appearing when the timer is done.

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

  • ApprowApprow Member Posts: 703

    @tatiang Omg that is amazing, thank you so much! I will study your logic tomorrow, I'm too tired right now (its already 22:20 here). But I kind of get how it works. Again, I really appreciate you took some time to help me:)

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

    You're welcome! :)

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

  • ApprowApprow Member Posts: 703

    @tatiang I just took a good look at the logic, and it looks really solid. Very easy to add additional power ups to the list, and it will come in handy for other projects that need this kind of number generation. Adding rareness to specific numbers will get to complicated I think. I modified the project a bit, now it will never repeat the same number twice. It will only repeat a number if only 1 power up is unlocked. by the way, the change attribute with game.selectedPowerup always stayed zero, not sure if this was correct? You made a pretty impressive demo here, I learned a lot from it.

    Cheers!

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

    Correction: the last part of the bottom rule should have had a timer:

    The game.selectedPowerup attribute then contains the final chosen value.

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

  • ApprowApprow Member Posts: 703

    @tatiang yes I figured:) have you seen my version where the final chosen value can't be repeated twice in a row? I'm not sure if it's the best way, but hey it works:D

Sign In or Register to comment.