Random integer question.

gesimundgesimund Member Posts: 33
edited November -1 in Working with GS (Mac)
Im trying to keep the global attributes down the a minimum and if I can't do this, then im going to need 10 or so global attributes. So, I need help with an alternative if there is one.

Im going to have about 10 different actors. I have a global integer attribute . There will be a button with a rule that says, if pushed generate a random number between 1-10. Then 10 different rules that say, if this number was generated, spawn this actor.

Thats all good, but then the thing that makes it complicated is I only want to spawn that particular actor a single time. If the button is pushed again, I want it to spawn one of the 10 actors that have not yet been spawned. So, is it possible at all to take that number out of the equation and still keep it random?

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    CodeMonkey has a demo (dealing with Time I think) that shows a way to have random numbers not duplicate themselves.

    It's a little tough without things like while loops and arrays, but it can be done.

    As far as global attributes, I wouldn't worry about the amount used. Both of my games both load/save over 160 Attributes. Plus there are more that are used and don't get saved. I haven't noticed a problem.
  • gesimundgesimund Member Posts: 33
    Oh wow! Ya, I was mostly afraid that too many global attributes could cause performance issues. Thats well over what I even imagined using for the entire game haha. Well, I'll look into that demo still though just as a learning experience.
  • ORBZORBZ Member Posts: 1,304
    I don't understand what your single global attribute does? hold a number between 1 and 10?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi gesimund, interesting prob, and deceptively complicated I thought (or I've made it overcomplicated, don't know). Anyhow, I've had a go; it "did my head in" for a while! I haven't even tested it though, so don't know if it would work or not (not finished, but hopefully there's enough there for you to do that). As you know, to obtain the effect you're after would take no more than 10 lines of code or so, in RealBasic or similar; ah well.

    I've only use 3 actors in my example, and as you'll see it's only for when the random number is 1. The same again but for 2 and 3 is needed. In your case, up to 10....quite a lot of attributes when finished I reckon, but as the other guys said, the amount shouldn't be a problem. And even if you finish, whether it'll work as you want or not, or it's the right way to go, I don't know... (disclaimer ;-) )

    The new attributes are: Actor1Pos, etc; Actor1Active, etc; Amount of Actors, Random number.

    Photobucket

    Hope it helps.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gesimundgesimund Member Posts: 33
    Wow.. I think its safe to say you went above and beyond. This helps me out a lot.

    Thanks for all the input from everyone, this pretty much resolves what I wanted to do. I'm still trying to master Game Salad right now so im not very helpful if someone else needs help. But any games you make, I'll make it a priority to get it and give high ratings.
Sign In or Register to comment.