SRL Archive - OSR Help

Need help choosing a random option of 2 strings


kingofbigmac

2012-04-28 10:54:38

I have a script already and it works. But it only allows you to choose only one option. You can change it to say big, or small. I want it to randomly pick it for me. I have been racking my brain to figure it out. I need to learn to code.

Justin

2012-04-28 10:58:41


x := Random(2);
Case x of
0 : TypeSendEx('Small',true);
1 : TypeSendEx('Big',true);
end;

Is that what you are after?

Abu

2012-04-28 11:00:50

From: [J]ustin

x := Random(2)
Case x of
1 : TypeSendEx('Small',true);
2 : TypeSendEx('Big',true);
end;



It's actually supposed to be:

x := Random(2)
Case x of
0 : TypeSendEx('Small',true);
1 : TypeSendEx('Big',true);
end;

kingofbigmac

2012-04-28 11:01:38

From: [J]ustin

x := Random(2)
Case x of
1 : TypeSendEx('Small',true);
2 : TypeSendEx('Big',true);
end;

Is that what you are after?


Looks right. I understand the code is easy to do. I will try it and see if it works.

[Error] (35:3): is ('=') expected at line 34

Justin

2012-04-28 11:03:27

From: abu_jwka
It's actually supposed to be:

x := Random(2)
Case x of
0 : TypeSendEx('Small',true);
1 : TypeSendEx('Big',true);
end;


Yep, just noticed it, was about to come back and edit my post!

From: kingofbigmac
Looks right. I understand the code is easy to do. I will try it and see if it works.

[Error] (35:3): is ('=') expected at line 34


Post the highlighted line please

kingofbigmac

2012-04-28 11:05:02

From: [J]ustin
Yep, just noticed it, was about to come back and edit my post!



Post the highlighted line please


x := Random(2)

Justin

2012-04-28 11:08:14

From: kingofbigmac
x := Random(2)


Weird…


program new;
var x : integer;
begin
writeln('Start of script');
x := Random(2);
Case x of
0 : writeln('This is 0');
1 : writeln('This is 1');
end;
writeln('End of script');
end.


Start of script
This is 1
End of script
Successfully executed.
Compiled successfully in 0 ms.
Start of script
This is 0
End of script
Successfully executed.

If you want you can PM (click here) me the script and I will take a look at it.

kingofbigmac

2012-04-28 11:11:38

PM sent

Rich

2012-04-28 13:59:04

You don't even need to put the whole x part.
case Random(2) of
will do that same job.

Abu

2012-04-29 07:39:57

From: Rich
You don't even need to put the whole x part.
case Random(2) of
will do that same job.


I think using x as a replacement will same some ms though. Not that it makes much of a difference, but certainly a good habit nonetheless. :)

Rich

2012-04-29 07:50:29

Using x:
Compiled successfully in 32 ms.
Hello
Successfully executed.
Not using x:
Compiled successfully in 31 ms.
Hello
Successfully executed.
Using if then else
Compiled successfully in 31 ms.
Hello
Successfully executed.

And to be honest, I don't really see how using unnecessary code is a good habit, but that's just my opinion.

Abu

2012-04-29 07:51:43

Oh well, guess I'm wrong :redface:

Daniel

2012-04-29 08:24:27

From: abu_jwka
I think using x as a replacement will same some ms though. Not that it makes much of a difference, but certainly a good habit nonetheless. :)


No it won't. It will only save a few microseconds if using it in a loop.

Abu

2012-04-29 08:25:29

From: Daniel
No it won't. It will only save a few microseconds if using it in a loop.


Well I was just trying to justify what [J]ustin wrote, I never do this myself :p

Home

2012-04-29 08:44:52

var
TSA :TStringArray;

begin
TSA := ['High', 'Low'];
WriteLn(TSA[Random(Length(TSA))])
end.


~Home