Spawning System Confused Meltdown!
beefy_clyro
Member Posts: 5,394
Hi Guys!
Having a bit of a mare creating a spawning system.
Basically, I have a shop where the player can purchase say 5 items in any order they want. Once they have bought an item, an attribute is switched to say that this is ok to spawn.
so;
Player buys item 3, attribute 'OkToSpawnItem3' is set to true ... Same with all the others.
Now the spawner needs to be setup in certain ways;
Can only spawn 1 item at a time.
It selects from available items its ok to spawn at random.
e.g. Item1, 3 and 5 are purchased and allowed to spawn.
Spawner randomly selects between those and sends one out.
Item2 is now purchased so it needs to now carry on sending one out at a time but will pick from item1, 2, 3, and 5
etc etc
Any ideas?
Cheers
Having a bit of a mare creating a spawning system.
Basically, I have a shop where the player can purchase say 5 items in any order they want. Once they have bought an item, an attribute is switched to say that this is ok to spawn.
so;
Player buys item 3, attribute 'OkToSpawnItem3' is set to true ... Same with all the others.
Now the spawner needs to be setup in certain ways;
Can only spawn 1 item at a time.
It selects from available items its ok to spawn at random.
e.g. Item1, 3 and 5 are purchased and allowed to spawn.
Spawner randomly selects between those and sends one out.
Item2 is now purchased so it needs to now carry on sending one out at a time but will pick from item1, 2, 3, and 5
etc etc
Any ideas?
Cheers
Comments
And rather unfortunately, I've hit that point where my brain can not focus anymore and can't see light at the end! Arrghhh shutdown!
Yes, a queue system is in order where you push purchased/unlocked items onto a table "stack" and then pop them off in random order.
There's even a handy-dandy ASCII drawing of a stack in the answers on this page: http://stackoverflow.com/questions/3825050/what-do-push-and-pop-mean-for-stacks
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I can't get to it right now but I can probably build a demo tonight.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I have attached the file in case it maybe of some use to anyone else
Or maybe I just misunderstood. For example, in your demo if you have 0 in the table and you add 4, it will pick random(0,4). I thought you actually wanted it to pick 0 or 4 in that case.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
When an item is purchased
-->add a new row and save the purchase ID/name to the row
Choose a random number between 1 and RowCount
-->spawn the item that matches that cell value
-->delete that row
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
These are one time unlocks. So when the player unlocks it, they need to always be available for the spawner, not pick once and delete
Then the algorithm is just:
• Add new row, change table value to unlocked item ID
• Pick random row and spawn the actor that matches that ID
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It has 1 column, this is what i used to put the unlocked id into (simulating its purchase)
So lets say the user has bought item 1 and 3, the table now has 2 rows, the 1st has a value of 1 and the 2nd has a value of 3.
I would like my spawner to then just randomly every x amount of time to pick either that 1 or 3 ...
Ideally, I say choose the value in row 1 or 2, but how do I specifically tell it to do that?
Timer every x seconds
.....Change Attribute self.tableRows to tableRowCount(tableName)
.....Change Attribute self.chosenRow to random(1,self.tableRows)
.....Change Attribute game.chosenItem to tableCellValue(tableName,game.chosenRow,1)
Then its up to you how to use game.chosenItem. You could have When game.chosenItem=1, spawn actor [1] and When game.chosenItem=3, spawn actor [3], etc.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Timer every x seconds
.....Change Attribute game.WhatPowerUp to tableCellValue(tableName),random(1,tableRowCount(tableName),1)
Then ...
When game.WhatPowerUp=1, spawn PU[1] and When game.WhatPowerUp=3, spawn PU[3], etc.
Seems to do the trick nicely
Thanks for your help