Spawning System Confused Meltdown!

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

Comments

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @Socks I tried AAA*sin( self.Time *BBB)+CCC and that didn't work either ;)
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    Tables I suspect, for each item purchased add column with that value, then randomly select from this table.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    edited February 2013
    I was thinking that maybe the case but lets say I have the 5 on a boolean and again its 1, 3 and 5, not sure how I would tell it to select from those rows and ignore the false ones in between?

    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!
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934


    I feel for ya man. I know exactly how your feeling right now.
  • SocksSocks London, UK.Member Posts: 12,822
    @Socks I tried AAA*sin( self.Time *BBB)+CCC and that didn't work either ;)
    Lol, you just need to change some of the letters around, it should work fine.

  • SocksSocks London, UK.Member Posts: 12,822
    I was thinking that maybe the case but lets say I have the 5 on a boolean and again its 1, 3 and 5, not sure how I would tell it to select from those rows and ignore the false ones in between?
    Because the 'false' ones don't exist ! You only add columns that have been purchased/unlocked.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I think @Socks stole your brain.

    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
  • beefy_clyrobeefy_clyro Member Posts: 5,394


    I feel for ya man. I know exactly how your feeling right now.
    One of those days mate, lack of sleep and staring at the project all day ... coupled with being ill, not a good combo! Good luck waking your brain!

    @socks @tatiang Totally understanding the logic :) Thats the kind of solution I was looking for .... HOWEVER ... I just cant set this up, any chance one of you could please knock up a quick demo to save my head from exploding? I'll be your best friend ;)

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

    I can't get to it right now but I can probably build a demo tonight.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @tatiang If you could that would be great! I'll owe ya :)
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @Socks @tatiang It's all good, I've managed to do a solution now! Thanks for pointing me the right way with logic. It seemed like I needed dinner and once I had that, my brain began to function somewhat again :)

    I have attached the file in case it maybe of some use to anyone else
  • SocksSocks London, UK.Member Posts: 12,822
    @Socks @tatiang It's all good, I've managed to do a solution now!
    :)>-
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2013
    I think you might need some more dinner. :P It looks like you're picking a random number between the values of the top-leftmost cell and the bottom-rightmost cell rather than picking a random row or column.

    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.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's how the algorithm looks (haven't had time to demo it yet)... note that it just uses one column:

    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
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @tatiang .... I just discovered that myself .. thats exactly what it is doing! hahaha
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Sorry, I'm not sure why I would delete the row?

    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
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Oh sorry, in that case you'd leave the rows intact. That's even easier.

    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
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    So in the example I uploaded,

    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?
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Right lets try this one ... I really don't understand how i'm milking this :))
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    To pick a random row:

    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.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    edited February 2013
    Ah ha, I see .. I went with;

    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
Sign In or Register to comment.