Random numbers

cnmeyer1980cnmeyer1980 Member, PRO Posts: 211

Hi everyone,

I hope you're all well.

I'm really hoping that someone on the GS forum maybe able to help me with a little bit of 'random' coding.

I've read through other posts about this, however I can't get it working, so sorry if this is something that has already been asked, I just can't get my head around it and maybe someone knows an easier way, or an easier explanation on what to do.

Basically, I have 12 squares (kinda like containers) every second I'm creating a random number between 1,12, and based on this number an actor is spawned inside one of the containers - this works well (and was very basic to do) - however, what I'm trying to do is - for example, if theres an actor in the 3rd and 7th (or more) containers, then the numbers being randomed only relate to the numbers that are currently not spawning an actor.

What I'd like is to be able to random number between 1,12 that are currently not on display.

I know my explanation is rubbish (again, sorry about that) - however I've uploaded the code below so you can hopefully see what I'm trying to do.

I'm not giving up as I think it has something to do with % however I'm not quite getting it.

Any help would be great guys, and as always I really appreciate your support.

Link: https://www.dropbox.com/s/jii7jino5dlrzkm/Random.zip

Cheers,
Chris

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    edited April 2014

    An easy way to do it (if I'm understanding you correctly) is to wait (sorry!) for the next release or use a nightly build.

    You can compare numerical values, for example in a table (which you can't do with the build you made your demo in).

    By changing a cell value to 1 or 0 you can tell if an actor has been spawned there.

    I noticed in your example you're not using tables - I would recommend looking up how to use them/potential uses.

    They are REALLY handy, trust me, and you'll be able to do a lot more with them in the new build.

    Hope that helps/nudges you in the right direction!

    QS =D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • cnmeyer1980cnmeyer1980 Member, PRO Posts: 211

    Hi QS,

    Thank you for the above and for the advise - I've never used tables before, for some reason the idea of them freaks me out, however, I really do need to look into them, and also, if it makes overall development easier in the long run, then..... I think I had better have a look at a couple of YouTube tutorials :smile:

    Thanks again,
    Chris

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

    Tables are very powerful and something you shouldn't avoid learning and using.

    As @quantumsheep said, the process of coding what you want to do is much, much easier with the Release Build or the next stable build because of tableSearch(), Loop over Table and other table features.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • cnmeyer1980cnmeyer1980 Member, PRO Posts: 211

    Hi @tatiang,

    Thank you for your message - I'm currently having a look at a couple of tutorials regarding tables - looking forward to tableSearch on the next build. For a change I'm going to concentrate on actually focusing on one thing at a time, so, first up - tables - thanks guys, I really appreciate your help.

    Cheers,
    Chris

Sign In or Register to comment.