Sorry struggling with this one. I’ve thrown a void main() and wrapped the contents. But I keep running into compile issues. And this alone won’t compile the ExecuteScript line. I tried finding something similar and also the examples on lexicon, even tried doing sometihng similar with LS script tool, ust to get an idea of what I need to get this working as is so I can understand it.
string RandomScript()
{
//pick a random script
string sScript;
int iSwitch = Random(6);
if (iSwitch == 0) sScript = "arena_0001";
if (iSwitch == 1) sScript = "arena_0002";
if (iSwitch == 2) sScript = "arena_0003";
if (iSwitch == 3) sScript = "arena_0004";
if (iSwitch == 4) sScript = "arena_0005";
if (iSwitch == 5) sScript = "arena_0006";
return sScript;
ExecuteScript (sRandomScript, object oArea);
}
You don’t need the “object” part before oArea in ExecuteScript.
Anyway, when the compiler reaches the return sScript; line, the script will end (and ExecuteScript will not run).
The compiler will throw errors with that anyway because you haven’t declared the string variable sRandomScript. Try this -
string RandomScript()
{
//pick a random script
string sScript;
int iSwitch = d6();
switch(iSwitch)
{
case 1 :
sScript = "arena_0001";
break;
case 2 :
sScript = "arena_0002";
break;
case 3 :
sScript = "arena_0003";
break;
case 4 :
sScript = "arena_0004";
break;
case 5 :
sScript = "arena_0005";
break;
case 6 :
sScript = "arena_0006";
}
return sScript;
}
// Then when you want to use your random script elsewhere in your code you would use -
ExecuteScript(RandomScript(), oArea);
To get the hang of scripting see this pinned thread (and bookmark it for future reference) -
Well, professionals might fairly point out that the code breaks when the number of scripts exceeds 9 (which can be fixed with a function that returns the number in the form NNNN) and when one of the scripts needs to be named differently for some essential reason (which can’t).
Ah, I see. Writing such code always requires a solid estimation, which range of numbers is to expect.
So the code is indeed somewhat fragile, but the original code from the op would be even more fragile … Well let’s add an error-response if the number exceeds the expected value
I didn’t go that route since I plan on having many scripts for this arena spawner. So the TR’s case statement works better for me.
I got the code working by just adding a include for the case statement script in a super basic script that just executes the random script. works great.
I kept trying to cram the ExecuteScript() into the case statement above - thinking that was the best way, just one script. I assume it’s entirely doable but having a separate script to just call the randomscript is also simple.
I attempted to add more scripts to this case and figured I just need to up the d# for int iSwitch = d6(); for he number of cases I have but just adding one script and changing it to d7 fails to compile with error: phrasing variable list.
And you won’t see. After all to be a die, the polyhedron must have a near-uniform probability distribution, which only the 5 platonic solids qualify for.
@Beleghost, use int iSwitch = Random(7) like you had before to “roll” a 7-sided die (or any-sided die, up to 32768). The d6() etc functions are its +1 shortcuts provided for convenience.
string RandomScript()
{
//pick a random script
string sScript;
int iSwitch;
do
{
iSwitch = d8();
}
while(iSwitch == 8)
switch(iSwitch)
{
case 1 :
sScript = "arena_0001";
break;
case 2 :
sScript = "arena_0002";
break;
case 3 :
sScript = "arena_0003";
break;
case 4 :
sScript = "arena_0004";
break;
case 5 :
sScript = "arena_0005";
break;
case 6 :
sScript = "arena_0006";
break;
case 7 :
sScript = "arena_0007";
}
return sScript;
}
// Then when you want to use your random script elsewhere in your code you would use -
ExecuteScript(RandomScript(), oArea);
Most times the code will pass through the do/loop just the once. If it gets an 8, it will reroll until it is not an 8.
Yeah, writing that every side has the same chance of being rolled was too boring
(Near-uniform because typical dice are less balanced than those used in casinos.)
With d6 of course. 1,2 = 1; 3,4 = 2; 5,6 = 3. Or a custom cube that has two 1s, 2s, 3s. d2 is even easier: odd = 1, even = 2.
OFF-TOPIC EDIT IF YOU LIKE TO ROLL
I also see that in 1-20 range, 3 (6/2), 5 (10/2), 9 (3&3), 16 (8&2) and 18 (6&3) can be directly emulated with platonic solids. 14 can if you represent it in base 12 as 12 (!), 15 is 3&5 and 7 is 14/2, which is crazy (and in hindsight apparently incorrect, oh well). 11, 13, 17 and 19 are of course impossible.