PDA

View Full Version : The ReadLn Function!



ronny.m.p
04-14-2007, 06:13 PM
Hello SRL community. I'm here to tell you about the ReadLn command. Everyone knows the writeln function but very few know the readln and it is quite useful!

What is ReadLn?

ReadLn is a function used to get information from the user. It is basicly a form that dosen't require any other codeing except one small procedure.

Where could i use ReadLn?

Use it where you need to get information from the user but don't want to have to go to the trouble of makeing a form ;)

What is the syntax?

The syntax is simple:
function Readln(question: string): string;
The question is statement is what you want to ask the user.

Useing ReadLn.

Just put:
ReadLn({question here});
where you want to ask the user your question. A box will pop up with your question and an edit box. The user puts the "answer" in the edit box and ReadLn returns the answer as a string.

Useing a variable to define the answer.

We need to use a variable to make the "answer" any use to us. So just make something like this:


var
Answer : string;


Working Example.

Here is a working example of ReadLn;


program ReadLnExample;
var
Answer : String;

procedure GetAnswer;
begin
Answer := ReadLn('What is your username?');
writeln(Answer);
end;

begin
GetAnswer;
end.


Feel free to + rep me if you like guide and please give feedback.

-Ronny

Jason2gs
04-14-2007, 06:25 PM
I 'spose it'd be helpful for some people :)

Martin
04-14-2007, 06:37 PM
I was bored and I made a script to show the possibilites.........


program New;

var SndBox, ManyBox : string;
var Done : Integer;

begin
ClearDebug;
SndBox:= Readln('What do you want to type');
ManyBox:= Readln('How many times?');
//Sendkeys(SndBox)
Writeln('Printing ' + inttostr(strtoint(ManyBox)) + ' Times');
Writeln('');
Repeat
Writeln(SndBox);
Done:= Done + 1;
until(Done = (strtoint(ManyBox)))
Writeln('');
end.

WhoCares357
04-14-2007, 07:25 PM
This is an interesting concept. Thanks for sharing.

Mjordan
04-14-2007, 07:27 PM
How could you use this for a script in RS/ what would be the point? Just wondering, cause I can't think of how.

Boreas
04-14-2007, 07:29 PM
Simple set up form, that's about it.

Mjordan
04-14-2007, 07:30 PM
Simple set up form, that's about it.

Ah ok I see.

Jason2gs
04-14-2007, 07:30 PM
Ye, a simple little shortcut ;)

ronny.m.p
04-14-2007, 07:32 PM
Yes and something like this is great for runescape:


program New;
{.include SRL/SRL.scar}
var
UserQuestion,PassQuestion,NickQuestion,SkillQuesti on,LocQuestion : string;


procedure GetAnswers;
begin
UserQuestion := readln('Username?');
PassQuestion := readln('Password?');
NickQuestion := readln('Nick name?');
SkillQuestion := readln('Skill?');
LocQuestion := readln('Player Location?');
end;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := UserQuestion;
Players[0].Pass := PassQuestion;
Players[0].Nick := NickQuestion;
Players[0].Skill:= SkillQuestion;
Players[0].Loc := LocQuestion;
Players[0].Active :=True;
end;

begin
GetAnswers;
end.

Farno Productions
04-15-2007, 12:48 PM
Wow! This is what I needed! Very helpful... at least for me!

ronny.m.p
04-15-2007, 04:42 PM
if you like it then you could rep me if you like ;)

JAD
04-15-2007, 07:47 PM
Just so you know ronny, its against the rules to ask for rep ;)

omfg2007
04-15-2007, 07:49 PM
decent tut.

ronny.m.p
04-17-2007, 07:38 PM
I didn't ask for rep i just said if you like it then you can feel free to if you want ;)

JAD
04-17-2007, 09:34 PM
You did say

if you like it then + my rep

not you could rep you, but to do it if he liked it ;) No big deal lol.. Just thought I'd explain to you the rules :p

ronny.m.p
04-17-2007, 10:57 PM
i hear ya..ill edit post :)

Rune Hacker
04-17-2007, 10:58 PM
What is rep for anyways :confused:

JAD
04-17-2007, 10:59 PM
Lol, reminding people to give you rep "If they want too" Is pretty much telling them too because you know they liked the tut ;) Rep is not supposed to be talked about at all. It really doesn't matter lol, just saying ;)

Edit: Runehacker, its just something that only you can see, that people rep your post. I forgot how to check it though, something under account management I believe :p

ronny.m.p
04-17-2007, 11:06 PM
Ok can we get back on topic now?

the scar noob
06-03-2007, 06:45 PM
So it's somekinda like the "prompt" function from JavaScript?
Can you somekinda like this?:
program Users_Age;
Var
Age: String;

Procedure Users_Age;
Begin
Age:= ReadLn('How old are you?');
Writeln(Age);
End;

Begin
Users_Age;
End.
And than you can use that further in your script, right?
Like:
program Users_Age;
{.include srl/srl.scar}
Var
Age: String;
Times, Age2 : integer;

Procedure Users_Age;
Begin
Age:= ReadLn('How old are you?');
Writeln(Age);
End;

Procedure WriteUsersInfo;
Begin
Age2:= StrToInt(Age)+1;
Times := 1;
Repeat
Writeln('Your '+IntToStr(Times)+' b-day');
Times := Times + 1;
Until (Times = Age2)
End;

Begin
Users_Age;
WriteUsersInfo;
End.
>> I know somekinda like stupid, but it's an example :P

EDIT: Plz can you also send a PM cause i probably gonna forget this thread cause of exams, tx :P

shaunthasheep
06-03-2007, 07:38 PM
no offence, wouldn't this go in the beginners section =p

ronny.m.p
06-03-2007, 08:00 PM
Ya i guess but alot of people dont know about it (even advanced).

shaunthasheep
06-03-2007, 08:12 PM
we no about.. alot of people just don't use it.

Dan Cardin
06-03-2007, 09:05 PM
y not use this instead of forms...like ronny said

program New;
{.include SRL/SRL.scar}
var
UserQuestion,PassQuestion,NickQuestion,SkillQuesti on,LocQuestion : string;


procedure GetAnswers;
begin
UserQuestion := readln('Username?');
PassQuestion := readln('Password?');
NickQuestion := readln('Nick name?');
SkillQuestion := readln('Skill?');
LocQuestion := readln('Player Location?');
end;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := UserQuestion;
Players[0].Pass := PassQuestion;
Players[0].Nick := NickQuestion;
Players[0].Skill:= SkillQuestion;
Players[0].Loc := LocQuestion;
Players[0].Active :=True;
end;

begin
GetAnswers;
end.


but add like this

program New;
{.include SRL/SRL.scar}
var
UserQuestion,PassQuestion,NickQuestion,SkillQuesti on,LocQuestion : string;


procedure GetAnswers;
begin
UserQuestion := readln('Username?');
PassQuestion := readln('Password?');
NickQuestion := readln('Nick name?');
SkillQuestion := readln('Skill?');
LoadQuestion:=readln('how many loads');
end;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := UserQuestion;
Players[0].Pass := PassQuestion;
Players[0].Nick := NickQuestion;
Players[0].Skill:= SkillQuestion;
Players[0].Active :=True;
end;

begin
GetAnswers;
end....and im sure u could add multi-player to readln if u wanted

ronny.m.p
06-04-2007, 08:51 AM
It's easier then forms :)

Dan Cardin
06-04-2007, 11:29 AM
i know....but would u be able to make multiplayer with it?...like
const
Loads:(answer)

procedure woot;
begin
answer:readln('how many players are you using');
for I:=0 to (answer) do
repeat
username[i]:=readln('username');
password[i]:=readln('password');
nickname[i]:=readln('nickname');
load[i]:=readln('how many load');
answer:=answer-1
until (answer:=0)
end;

procedure DeclarePlayers;
begin
howManyPlayers := (answer);
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := Username;
Players[0].Pass := Password;
Players[0].Nick := Nickname;

Players[1].Name := Username;
Players[1].Pass := Password;
Players[1].Nick := Nickname;

Players[2].Name := Username;
Players[2].Pass := Password;
Players[2].Nick := Nickname;
end;

begin
woot;
DeclarePlayers;
end.

that wont nessisarily work...just an example

Boreas
06-04-2007, 12:34 PM
procedure DeclarPlayersReadln;
begin
try
HowManyPlayers:=strtoint(readln('how many players are you using'));
except end;
NumberOfPlayers(HowManyPlayers);

for CurrentPlayer:= 0 to HowManyPlayers-1 do
begin
try
Players[CurrentPlayer].Name:=readln('Player['+inttostr(CurrentPlayer)+']'+chr(39)+'s Username');
except end;
if Players[CurrentPlayer].Name='terminatescript' then terminatescript;

try
Players[CurrentPlayer].Pass:=readln(Players[CurrentPlayer].Name+chr(39)+'s Password');
except end;
if Players[CurrentPlayer].Pass='terminatescript' then terminatescript;

try
Players[CurrentPlayer].Nick:=readln(Players[CurrentPlayer].Name+chr(39)+'s Nick');
except end;
if Players[CurrentPlayer].Nick='terminatescript' then terminatescript;

try
Players[CurrentPlayer].Integer1:=strtoint(readln(Players[CurrentPlayer].Name+chr(39)+'s will do how many loads'));
except end;
if Players[CurrentPlayer].Integer1=0 then terminatescript;
end;
try
CurrentPlayer:=strtoint(readln('Which Player will start?'));
except end;
end;

begin
setupsrl;
DeclarPlayersReadln;
end.

Try that

Bobarkinator
06-04-2007, 01:46 PM
Boreas to the rescue :spongebob:

the scar noob
06-04-2007, 02:31 PM
Sorry that i 'm daying this, but why doesn't anyone answers my question?
Omg :)

Boreas
06-04-2007, 02:34 PM
Yes

Dan Cardin
06-05-2007, 11:00 AM
holy crap Boreas...that is amazing...thats way better and simpler than what i wouldve come up with...i wrote sumthing earlier...and it was like 40 lines...ty!!

question though...for the which player starts....would u put the name or the number...number, right?


y doesit only do up to 2 players?

Boreas
06-05-2007, 03:12 PM
Which player starts is a number.

It should do as many as you want. Remember if you do 3 players, they will be 0 1 and 2.


By the way, what I posted above was just to prove what Readln could be used for if you really wanted. But I would suggest using this instead.

program New;
{.include srl/srl.scar}
{.include srl/srl/misc/playerform.scar}

begin
setupsrl;
FileName:='Team1';
setupplayers;
end.

Dan Cardin
06-05-2007, 06:55 PM
im not quite sure i get what u mean with the
program New;
{.include srl/srl.scar}
{.include srl/srl/misc/playerform.scar}

begin
setupsrl;
FileName:='Team1';
setupplayers;
end.
...but i typed in 7 for the number of players...and it only did 2
EDIT: sry nope it works for all past 2...yep

the scar noob
06-05-2007, 08:37 PM
Yes

Thanks, i get it than :P
Btw you also know JavaScript?

Boreas
06-05-2007, 09:01 PM
Np. I know a little bit of a few languages, but only really SCAR.

Dan Cardin
06-06-2007, 09:29 PM
is there any way where u could make more than one question come up in one window?...like an ultimate form, without all those extra lines...like putting ands in between them...and having them all pop up at once(even if they're in different windows...to make it easier to understand

Boreas
06-07-2007, 03:47 AM
Not that I know of. Learn forms or use setupplayers :p

Dan Cardin
06-07-2007, 10:29 PM
yea u posted something about that earlier
program New;
{.include srl/srl.scar}
{.include srl/srl/misc/playerform.scar}

begin
setupsrl;
FileName:='Team1';
setupplayers;
end. ill look it up...but if i cant find...can u tell me what it is?
EDIT: not sure i really get it...so it just opens a form...and asks all the things in your declare players?noo.....hmm its says it opens a form...but why make real forms if this just opens one, without all the form work...why make real forms?

EDIT2: ohhhhh...i've seen this before..i tried that mini-script u put up ...that i re-posted, and it came up...but how would u make it work for a specific script...1 where u wouldnt need the loc or the skill, like a buyer. u cant really change those.instead of those 2 i would need them to type in a item type, number of loads, and pin number.:confused:

Boreas
06-08-2007, 02:25 AM
If you want stuff that settupplayers doesn't have, you need to write (or get someone else to write - there are a couple people doing it I think) a custom form.

Dan Cardin
06-08-2007, 11:24 AM
lol...who's making custom forms?!

the scar noob
06-08-2007, 08:37 PM
Np. I know a little bit of a few languages, but only really SCAR.

k, SCAR, mhmm... can you tell me how to use interscar messages?

dialeyj2
06-09-2007, 09:19 PM
cool i found out wut readln was last nite and today i learned how to use it

ronny.m.p
06-09-2007, 09:50 PM
For more then one question just ask two questions and sepearte answers with a space then use the string function in scar Copy to copy the part of the answer before the space and then use another variable for the answer after the space. I'll make a script later to demonstarte.

Dan Cardin
06-11-2007, 12:45 AM
*sits at attenttion for hours*