Help With Table Coding?

Hello! :D
Quick question. I have a star system in my game and use a simple star system to operate it. What i am now trying to do is make a system where you need to obtain a certain amount of stars to unlock new worlds, similar to the game "Cut The Rope". Im not sure how to do this with tables, but i would probably need a line of code that says "When the sum of all numbers in row 1 reach 50, unlock new world"

How can i accomplish this? Any help would be greatly appreciated. Thanks! :)

Comments

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


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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    What's up with the video's can see the one you just posted?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    What's up with the video's can see the one you just posted?
    I don't know. I just copied and pasted it from my post and it seems okay now.

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

  • mrpacogpmrpacogp Member Posts: 400
    I use a table for save attribs for each lv, you can use another to sum all start found it really?
  • jblb2424jblb2424 Member Posts: 65
    My apologies i don't think i explained clearly enough. I do not need a level unlock system for each level. My game works so that every level is unlocked. However, to unlock new worlds, you must collect a certain amount of stars from the levels...lets say 50. Once 50 stars are obtained collectively from world 1, world 2 will be unlocked. How can i do this? Thanks so much for the help so far!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    Make two tables, one for StarsFound and one for StarsNeeded. In the StarsNeeded table, type in an integer value in each row for the number of stars needed for the corresponding level to be complete.

    Then add an actor that checks the table based on some condition (e.g. each time you collect a star):

    Change Table Value StarsFound,game.Level,1 to tableCellValue(StarsFound,game.Level,1)+1

    Change Attribute self.StarsFound (integer) to tableCellValue (StarsFound,game.Level,1)

    When self.StarsFound is greater than or equal to tableCellValue(StarsNeeded,game.Level,1)
    .....Unlock the next level


    *The Change Attribute statement is needed because you can't directly compare two table cell values in a rule.

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

  • jblb2424jblb2424 Member Posts: 65
    edited December 2012
    Thanks tatiang! That's very clever and i will use it. I just have one more question. Is there a way to make a displayed countdown of how many stars you need until the next unlock based on your code?

    Lets say i need 50 more stars to unlock world 2 again. If i collect 2 stars in level one and and 3 stars in level two, I want world 2 to still be locked and say "45 more stars needed" How can i do this using the code you gave me? Thanks so much for the help so far its really helping my game come along :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If the player needs 50 stars each time to unlock a new level, just set game.StarsNeeded (index) to 50. Each time the player collects a star, do Change Attribute game.StarsNeeded to game.StarsNeeded-1. Then have an actor with DisplayText game.StarsNeeded. And then have a rule that says When attribute game.StarsNeeded=0, (unlock the next level and...) Change Attribute game.StarsNeeded to 50.

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

  • jblb2424jblb2424 Member Posts: 65
    Thanks a bunch tatiang this helps immensely and i applied it to my game. I just have one bug though. I am stuck on trying to implement the countdown because my game works so that if the character dies in, lets say level 1, the stars collected resets back to 0. So basically a player must complete the level before anything pertaining to the star count is changed. How can i fix this? Thanks a bunch :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Why is it a problem if game.StarsNeeded resets to 50 when the character dies? Do you want it to do that or not?

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

  • jblb2424jblb2424 Member Posts: 65
    sorry i worked it out. Everything is working perfectly i cant thank you enough :)
Sign In or Register to comment.