This may be a dumb question, but I am a bit rusty with HamsterSpeak. And by "a bit" I mean "extremely."
Is there a way to create an array containing multiple variables? What I'm trying to do at the moment is to write a script that examines objects to see if they'll work for what I'm intend them to do, add the viable objects to an array as variables, and then randomly select a variable from the array to give me a single object to work with during the remainder of the script.
I wrote up my answer as a wiki article:
http://rpg.hamsterrepublic.com/ohrrpgce/Fake_arrays
Alternatively, the specific uniform random selection task you described can be done without an array, using stream processing techniques. Iterate over all the candidate objects doing the following (pseudocode):
There! Now you know how to handle "Big Data".
http://rpg.hamsterrepublic.com/ohrrpgce/Fake_arrays
Alternatively, the specific uniform random selection task you described can be done without an array, using stream processing techniques. Iterate over all the candidate objects doing the following (pseudocode):
Code:
current selection := -1
count := 0
for (candidate in candidates) do (
if (candidate is suitable) then (
count += 1
# select this item with probability 1/count
if (random(1, count) == 1) then (current selection := candidate)
)
)
# handle the case count == 0, otherwise use current selection
current selection := -1
count := 0
for (candidate in candidates) do (
if (candidate is suitable) then (
count += 1
# select this item with probability 1/count
if (random(1, count) == 1) then (current selection := candidate)
)
)
# handle the case count == 0, otherwise use current selection
There! Now you know how to handle "Big Data".



