using and saving inventory with tables

digitalzerodigitalzero Member, BASIC Posts: 639
I am creating a game that has over 30 individual guns that you can attain... the way that it works is that you have a certain amount of coins that you can get and you can use your coins to buy more weapons, characters, ect. it would be something like jetpack joyride as far as purchasing and saving... does anyone know where i can either find a tutorial on how to do this or steer me in the right direction because i would absolutely hate to have to make an attribute individually for each gun because thats at least 30 attributes that i could go without someone please help me!

Comments

  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    So... this is possible with tables.
    Here's what you would do:

    Create a table with 30 rows and 2 columns.
    Now, write the names of your different guns in the first column. Then, put a 0 for all the rows in the second column.

    Now, just make a rule that turns those 0's to 1's when the certain gun in unlocked, and then have a rule that makes sure people can only use a gun one the value in the same row as it, but one column over, is = to 1.

    Hopefully that makes sense. Tag me (@...) if you need any clarification or further help.
    - Thomas
  • digitalzerodigitalzero Member, BASIC Posts: 639
    @snapfirestudios that doesn't make any sense to me at all LOL... how would i coincide the image to the gun and also would it be easier for me to just use a boolean... IM CONFUSED AS !@#$%. excuse my french lol
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    @snapfirestudios that doesn't make any sense to me at all LOL... how would i coincide the image to the gun and also would it be easier for me to just use a boolean... IM CONFUSED AS !@#$%. excuse my french lol
    Ok, I will explain it in more depth this afternoon. I have to go for now.
    - Thomas
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Hey @digitalzero -

    So you're trying to make a store? We have a tutorial for that - search it up in GSHelper.com.
  • digitalzerodigitalzero Member, BASIC Posts: 639
    @braydon_sfx and @snapfirestudios i just checked it out and thats the tutorial that i have seen before... unfortunately my game is a little different... here is some rules i have in place to give you an idea of what im doing

    first off, i have an interger attribute named "guns purchased"

    on my scene there are two buttons that allow you to go to the next gun and the previous gun.. on those buttons i have the rules set as if touch is pressed then change attribute "game.guns purchased to (game.gun purchased+1)%31" of course to get to the previous gun its the same rule except the "+1" is a "-1"

    i have one image that is coinciding with the guns purchased behavior for example if "attribute game.guns purchased =1" it will show the image of the first gun if it equals 2 it will show the image of the next gun ect.

    when these images change if you have purchased the gun it will show an image of "purchased"

    now here is where the table thing comes in... i have a table labeled inventory and it has all 31 guns in it in the table i have two columns one is a boolean that tells if you purchased the gun or not and the other is an integer that will take the cost away from the guns purchased if you have not purchased the gun already

    there is also a purchase gun that i need to coincide with the table so that people know which gun they have purchased and which ones they are needing to purchase.

    so basically i need the table to coincide with the "guns purchased" attribute and I am also needing it to go with the purchase button i have set in place.

    I hope that gives you more of a clear understanding on what I am trying to do... its difficult to me because i honestly SUCK at tables but this is something very very important that I am going to implement with my game... if i can just understand how to do this i think i will be set to go!
  • baboybaboy Member, PRO Posts: 93
    edited June 2013
    ok let me try this.

    1. Make a 3RD column in your table "GunName" and name each row in the 3rd column gun1 to gun31. make sure your images are also named gun1.png to gun31.png

    2. instead of making the attribute "guns purchased" an INTEGER, make it a TEXT attribute (this is a game attribute) (YOU REALLY DON'T NEED THIS BECAUSE YOU ALREADY HAVE A TABLE FOR THE GUNS PURCHASED BUT FOR TESTING PURPOSES ADD THIS)

    3. Create another game attribute "CycleThruGuns". make this an INTEGER. place this rule in your 2 buttons where in you cycle thru your guns:

    (right button)
    when touch is pressed
    change attribute game.CycleThruGuns to game.CyclethruGuns+1,
    (left button)
    when touch is pressed
    change attribute game.CycleThruGuns to game.CyclethruGuns-1

    4. Make an INTEGER attribute "GunNumber" in your STORE ITEM Actor (if you dont have a STORE ITEM ACTOR, create one. this will be the actor that will display the gun images and where the user can buy your guns)
    5. Make an INTEGER attribute "ItemState" in your STORE ITEM Actor
    6. Make an BOOLEAN attribute "Purchased?" in your STORE ITEM Actor
    7. Make these rules inside your Store Item:

    Constrain Attribute self.GunNumber to game.CycleThruGuns
    Constrain Attribute self.Purchased? to tablecellValue(GunsTable,GunNumber,1)

    (change image rule)
    if self.Purchased? is FALSE
    -change attribute self.image = tablecellValue(GunsTable,GunNumber,3)..".png"
    -change self.ItemState = 0
    Otherwise
    -change attribute self.image = PURCHASED.png
    -change self.ItemState = 1

    (buy rule)
    NOTE: (LETS ASSUME THAT YOUR PURCHASE BUTTON IS THE STORE ITEM ITSELF, IF YOU HAVE A SEPARATE PURCHASE BUTTON, U NEED TO ADD A FEW MORE THINGS. BUT BASICALLY THIS IS IT)

    If ItemState = 0
    When Touched is Pressed

    -change Table Value
    Table : GunsTable
    Row : self.GunNumber
    Column : 1
    Value : TRUE
    -SAVE TABLE - Guns Table
    -change attribute game.guns purchased =
    game.guns purchased..tablecellValue(GunsTable,GunNumber,3) (AGAIN YOU DON'T REALLY NEED THIS :) )
    -game.gold = game.gold - tablecellValue(GunsTable,GunNumber,2) (you can create a more complex rule if gold is not enough then do this but this is the simple one)


    I tried to work with what you had. Hope this helps :)
Sign In or Register to comment.