A better system for randomization?


#1

Hello CoG, I am here today to ask for help making an easier way to randomize things. Right now, I am working on a simulation game that lies heavily on randomization. What I would like aid with, is how to make certain things unselectable a second time while randomizing. For example, what I can think of is this,

`
*temp checker1
*set checker1 0
*temp checker2
*temp checker3
*set checker2 0
*set checker3 0

*label back
*temp var
*set var 0
*rand var 1 3

*if var = 1
*if checker1 = 0
Do something
*set checker1 1
*goto back
*else
*goto back
*if var = 2
*if checker2 = 0
Do something
*set checker2 1
*goto back
*else
*goto back
*if var = 3
*if checker3 = 0
Do something
*set checker3 1
*goto back
*else
*goto back
`

Is there any way you guys can think of to improve this method, or make it easier. Danke!


#2

I use rand die_roll command and work fine I could even do something with a probability 1 1000 or even more but I don’t know if that’s what you like.
Edit: never mind I don’t know how make yours more easy mine is similar but using die roll like a fixed variable in mygame.js so I don’t use temp


#3

I coded a complete system for similar behaviour, it should copy and paste straight into games, and has basic documentation: http://choicescriptdev.wikia.com/wiki/System_mini-scenes

Otherwise, I’d refer you to the *gotoref and *setref commands:

They are your best friend when it comes to dynamic game direction and content generation :stuck_out_tongue:

If you’re looking for something else entirely (I may have misunderstood), could you please give a little bit more detail?


#4

@CJW
I think you have misunderstood me, let me elaborate. Say I want to generate a number 1 - 80, the first number may come out to 41, I want to know if there is an easier way to make it so that 41 will never be picked again.
EDIT: nvm, didn’t see the first part lol.


#5

@TIYF

You could use an array in JavaScript or you could simulate one using *gotoref and *setref - but it’s somewhat long-winded.

How many times are you going to roll?


#6

@CJW about 40 for this particular situation, I plan on larger amounts later though. See, this is basically just to randomize days that happen in an abridged school year. Therefore, your method on the wiki works. Thanks for showing it to me


#7

@TIYF

Happy (school) days then! :smiley:
I’m glad to hear it, the alternative would have involved 40+ temps and a loop (at least), so you got lucky there, I think. ^^
Best of luck with the rest of your game!

I know the system will also include that many variables but all the nasty loops and evaluations are done for you. Please do let me know if it causes any problems, it shouldn’t but I don’t think anyone has used it thus far… So I wouldn’t know for sure.