Post new topic    
Slime Knight
Send private message
Variable arrays? 
 PostFri Feb 06, 2015 12:35 am
Send private message Reply with quote
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.
Metal King Slime
Send private message
 
 PostFri Feb 06, 2015 2:50 am
Send private message Reply with quote
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):
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


There! Now you know how to handle "Big Data".
Slime Knight
Send private message
 
 PostFri Feb 06, 2015 4:33 am
Send private message Reply with quote
Thanks! That's a bummer, I was hoping actual arrays were hidden in there somewhere and I just wasn't seeing it. I'll try these alternative methods, though.
Slime Knight
Send private message
 
 PostFri Feb 06, 2015 6:30 am
Send private message Reply with quote
I just noticed there's a Q&A forum now. V
Display posts from previous: