SRL Archive - OSR Intermediate Scripting Tutorials

a little usefull function: readln


Awkwardsaw

2009-07-11 03:50:16

i was lurking through the SCAR help file and i found this little neat function:
function Readln(question: string): string;

what this does, is open up a little pop up menu, and asks a question, specified by "question", and returns what you type into the edit box.

run this little script:
program New;
begin
if readln('Is this cool?') = 'no' then exit;
writeln('Your cool too!');
end.

as you can see, if readln returns no(if you typed it in) then it will exit.

how this can be used, is lets say you made a version checker, you can say
program New;
begin
if getversion <> version then //your own version checker stuff
begin
if readln('This script is outdated! Would you like to continue the script?') = 'no' then
terminatescript;
end;
writeln('Script up to date');
end.

or, something else can be:
program New;
var s: string; c: integer;
begin
s:= readln('How many cycles do you want to do?');
repeat
inc(c);
writeln('test');
until c = strtoint(s);
end.

i hope you get the main idea of this :)

Extra stuff
also, i got this idea from Da Ownder, to use "GetApplication.MessageBox". this is also very simple, but just incase you dont know i will try to explain.

GetApplication.MessageBox('Message', 'Title', typeofform)

this also makes a popup menu, but instead of an edit box, it gives buttons, based off of "typeofform". there are 7(i think) different types of forms, all with theyre different uses. for this example we will use 4, and use it in a version checker.

program New;

begin
if getversion <> ver then
if GetApplication.MessageBox('This script is outdated! Would you like to continue the script?', 'Continue?', 4) = mrno then
begin
writeln('Terminating script');
wait(2000);
terminatescript;
end
writeln('Moving on');
end.

this opens up the menu, and will ask the question. either hit "yes" or "no".
there really isnt much else to explain, so i will let you play around with it a bit :p

i know this is a small and simple tut, but not a lot of people seem to know about this, or know how it can be utilized.

Da 0wner

2009-07-11 04:15:04

MessageBox is better for your version checking thing.

program New;

begin
if GetApplication.MessageBox('This script is outdated! Would you like to continue the script?', 'Continue?', 4) = mrNo then
TerminateScript;
end.

Awkwardsaw

2009-07-11 04:17:14

From: Da 0wner
MessageBox is better for your version checking thing.


MessageBox? mind showing me the function/ procedure parameters? its not in the little ctl + space thing

Da 0wner

2009-07-11 04:20:05

I posted an example.

But it's MessageBox('Text to display.', 'Title', MessageType);

Returns the modal result. MessageTypes can be found by just going through each of the numbers 0-6.

Awkwardsaw

2009-07-11 04:26:21

alright, i'll look through it i guess, and maby add it in the tut if i understand fully, if you dont mind :p

Da 0wner

2009-07-11 04:28:49

Sure, I don't care :p. Credit me though for telling you :).

Awkwardsaw

2009-07-11 05:29:27

oo. i think i like this =p i'll add it in, with added credits ofcorse :p

Blumblebee

2009-07-11 11:37:11

look at Dan Cardin's form tutorial for stuff like MessageBox and other neat form stuff, thats where i learnt it all.

Also, cool tut never really knew the use of Readln before.