PDA

View Full Version : The impossible script?



Trinitis
05-16-2005, 04:22 PM
I'm needing help forming ideas on how to produce a script.

This script needs to preform a random action (picked from a preset number of options) at random times.

Any ideas?

Drew2
05-16-2005, 04:39 PM
Not possible with the StormFront/Wizard scripting engines. For a reason, I'm sure.

Latrinsorm
05-16-2005, 04:40 PM
How random? Not too hard to produce random-ish numbers.

Bobmuhthol
05-16-2005, 04:40 PM
I'm going to assume that Jamus put in a random function. The solution: get his scripting engine.

Drew2
05-16-2005, 04:41 PM
If you're talking about the whole Match-with-time thing, that's dumb.

Trinitis
05-16-2005, 04:41 PM
Originally posted by Latrinsorm
How random? Not too hard to produce random-ish numbers.

I'd like it to be as random as possible. The script is going to be used for RP, not hunting :) I'd say more, but it'd ruin the idea :)

Sean of the Thread
05-16-2005, 04:46 PM
What is with the sudden influx of scripting discussion the last couple days?

Latrinsorm
05-16-2005, 04:47 PM
I need to check my other comp, but someone posted on the official boards a version of it that could be done in SF. Maybe in research and investigation?

I am not talking about match-with-time.

Trinitis
05-16-2005, 04:47 PM
Well, as for my topic. I've been trying to think of a way to do it for a month now. I'm still drawing a blank, so I figured I'd call in the reserves.

BigWorm
05-17-2005, 04:34 AM
Impossible? Not really. Use this forum's search functions and you'll find a discussion that lead to a (psuedo-)random number generator a few months ago.

Because there is no usable way to get TRUE random numbers on a computer, they all use an alogrithm. Google for random number algorithm, and you'll get some good hints. This is only going to be feasible in StormFront, because you'll need COUNTER MULTIPLY/DIVIDE and can probably make use of more variables. Remember that the only arithmetic functions you have are +,-,*,/, which will force you to be a bit more creative with you algorithm because most of them on the web are going to use atleast the MOD function.

Once you figure out an algorithm, you'll need a seed number of large enough size. Gemstone time is NOT a good seed, atleast by itself because its small and too regular. Last time, I saw people talk about using the number of people in the game, which is good, but still not very big. Better things to use are current exp/fame, fame of the umpteenth person on the fame list, and number of punctuation marks in room description/news article/etc. Just combine two or more together and you'll have a suitably large, randomish integer to use. (Remember to watch out for SF's interger overflow, can't remember what it is off hand, should check).

HarmNone
05-17-2005, 04:59 AM
Sounds like, if you all put your heads together on this issue, you'll find a way to do it. It would really be a fun project, I'd think. :)

Latrinsorm
05-17-2005, 05:29 PM
The one I had was a mod one. :( Sorry!

Bobmuhthol
05-17-2005, 06:21 PM
The best way to do it is make a scripting engine that randomizes a number based on how many seconds have passed since midnight, then use INT(RND * X + Y), where X is the upper bound and Y is the lower bound.

sahra
05-19-2005, 02:54 AM
Sure it's possible. There are various ways of obtaining random seeds -- in a roleplaying context, you could ask the user to initialize the script with a random number as an argument, pass that to a random-number generator (RNG), then preserve the last value output by the RNG as a variable, using that as the seed for subsequent runs. During a given run, the RNG accepts its own output as input for the next iteration, producing as many pseudo-random numbers as you want.

For most purposes, this is fine -- as posters have said, the output isn't "really" random (in fact, the sequence of numbers produced by the RNG is entirely deterministic for each seed), but it's unknown in advance to the user and hard to predict.

There are a zillion RNGs -- the real question is which are easiest to implement in StormFront's slow, retarded scripting language. The one I've coded here is a bad old IBM RNG called RANDU, where each iteration is produced by multiplying a fixed value by the prior iteration's output, and taking the result modulo a certain 'period' (which becomes, effectively, the span of possible numbers output by the algorithm). A real RANDU implementation uses a much larger period, but this is difficult in StormFront, because there are strict limits on integer size (I forget what they are, just now, but they become annoying in this application).

The core algorithm produces random numbers between 0 and 65535, which is, I imagine, a large enough period for most Gemstone applications. Output values are then masked into a range by integer division. I set up this test to show the output of a 100-sided die, but you could mask this to return small random integers in any range. The first time you run it, enter a random integer argument as the seed. Afterwards, run it w/o args to produce the next random integer in series.

Seems to work ... that is, the output looks randomish to me. (grin)

DEBUG OFF

setvariable a 1028
setvariable per 65539
if_0 goto getseed
goto random
getseed:
setvariable seed %1

# modified IBM RANDU algorithm: x2 = ax1 % per
random:
counter set %seed
counter multiply %a
setvariable ctr %c
counter divide %per
counter multiply %per
setvariable ct2 %c
counter set %ctr
counter subtract %ct2
setvariable seed %c

# counter now contains large random integer
# masking example: 0 - 99 (100-sided die)

setvariable ctr %c
counter divide 100
counter multiply 100
setvariable ct2 %c
counter set %ctr
counter subtract %ct2
echo %c

[Edited on 5-19-2005 by sahra]