Need advice with random scoring.

Hi. I'm making a game where the player runs a store, with the customers coming in and buying products. I made it so that the item the customer buys is random, selected from a table. But I can't seem to figure out how to make the game add the price of the item to the players money attribute. Is there a tutorial or an already answered question about this kind of thing? Tried to look but couldn't find one, I might have missed it. Thanks in advance for help.

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Nekku, does your table include a column with the price for each item?

    Something like:

    • Column 1 = Product description
    • Column 2 = Product price

    Now, you probably choose a random row number (e.g. self.RandomRow), to get the random product being bought.

    This row number is now also used to add the corresponding price from column 2:

    Change attribute: 
    game.TotalMoney 
    to 
    game.TotalMoney + tableCellValue(game.ProductsTable, self.RandomRow, 2)
    
  • NekkuNekku Member Posts: 6
    edited October 2015

    Yes, there is a column for the item price. Thank you very much, @Hopscotch, that is exactly what I needed. Now I feel really silly for not figuring that out.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    Glad I could nudge you into the right direction @Nekku :)

Sign In or Register to comment.