SRL Archive - Help

Proper Writeln function


rj

2013-01-27 19:23:39

So i started using functions in my scripts more to improve them but I was wondering if i could write a function without having to use a Boolean. I currently use:
function WriteDebug(): boolean;
begin
ClearDebug;
Writeln('*****************************');
Writeln('Status:' + Status + '');
Writeln('Spice steals:' + IntToStr(Stole_Spice) + '');
Writeln('Ruby steals:' + IntToStr(Stole_Ruby) + '');
Writeln('Runs:' + IntToStr(Runs) + '');
WriteLn('Goal:' + '[' + How_Steal + ']'
+ '|' + IntToStr(StrToInt(How_Steal) - Steals)
+ ' Left to steal| ['
+ IntToStr(Round(Steals * 1.0 / StrToInt(How_Steal) * 100)) + '%]');
Writeln('*****************************');
end;

but I am tired of getting:

[Hint] C:\Simba\Scripts\silabtheiv.simba(32:10): Variable 'Result' never used at line 31

It spams up my debug box everytime I compile.

Any tips?

Sin

2013-01-27 19:40:01

Function Somthing:Integer/String/TPoint;?

riwu

2013-01-27 19:43:19

Your 'function' does not make use of the result, hence the declared result becomes an 'unused' variable, hence the hint.
Simply rename 'function' to procedure instead and remove the result declaration.
i.e.

procedure WriteDebug();

Ian

2013-01-27 19:46:28

Maybe I'm missing something, but why would you want to use a function for this instead of a procedure? The reason you get that result not used thing is because a function returns something. A boolean function retuns a true/false. That message means that you don't use what it returns, so you may as well use a procedure :/

rj

2013-01-27 20:26:03

From: BMWxi
Maybe I'm missing something, but why would you want to use a function for this instead of a procedure? The reason you get that result not used thing is because a function returns something. A boolean function retuns a true/false. That message means that you don't use what it returns, so you may as well use a procedure :/


Then it has to skip to the procedure doesent it?

Sjoe

2013-01-27 20:27:52

From: rjj95
Then it has to skip to the procedure doesent it?


you want it to write the progressreport if it done something?

Then why not try smthing like:
if DoingSomething = True then progressreport;

EDIT: OFFTOPIC

Look at this post lol

Shame on you!

rj

2013-01-27 20:33:17

From: Sjoekeloe
you want it to write the progressreport if it done something?

Then why not try smthing like:
if DoingSomething = True then progressreport;

EDIT: OFFTOPIC

Look at this post lol

Shame on you!


why would you gravedig something I already confessed to from 2 years ago?

Sjoe

2013-01-27 20:38:04

Didn't see your confession sorry ;)
Cause It was funny when I saw that post.

Flight

2013-01-27 20:39:42

Quick and dirty: Functions are procedures that will return a result. Procedures are just blocks of code that do whatever you want them to, no results are returned. So if you're doing a progress report and all it does it call "writeln" a few times then it's better just to declare it as a procedure, not a function.

Here's an example:


Function TeleportToBank: Boolean; //True or False will be returned from this
begin
if not LodestoneTeleport('Lunar Isle') then
Exit;

Result := WaitFunc(@NearBank, 10, 14000);
{
Or...
if WaitFunc(@NearBank, 10, 14000) then
Result := True
else
Result := False;
}
end;

Procedure TeleportToBank; //Nothing is returned
begin
if not LodestoneTeleport('Lunar Isle') then
Exit;

WaitFunc(@NearBank, 10, 14000);
end;

Main loop:


if InvFull then
if TeleportToBank then //If this function returned true, then...
Writeln('We are at the bank!')
else
Writeln('Wtf happened man? I quit...');

//Or, for a procedure...

if InvFull then
TeleportToBank;

Understand? ;)

Ian

2013-01-27 21:15:56

From: rjj95
Then it has to skip to the procedure doesent it?


What do you mean by skip to the procedure?

rj

2013-01-27 21:46:13

From: Flight
Quick and dirty: Functions are procedures that will return a result. Procedures are just blocks of code that do whatever you want them to, no results are returned. So if you're doing a progress report and all it does it call "writeln" a few times then it's better just to declare it as a procedure, not a function.

Here's an example:


Function TeleportToBank: Boolean; //True or False will be returned from this
begin
if not LodestoneTeleport('Lunar Isle') then
Exit;

Result := WaitFunc(@NearBank, 10, 14000);
{
Or...
if WaitFunc(@NearBank, 10, 14000) then
Result := True
else
Result := False;
}
end;

Procedure TeleportToBank; //Nothing is returned
begin
if not LodestoneTeleport('Lunar Isle') then
Exit;

WaitFunc(@NearBank, 10, 14000);
end;

Main loop:


if InvFull then
if TeleportToBank then //If this function returned true, then...
Writeln('We are at the bank!')
else
Writeln('Wtf happened man? I quit...');

//Or, for a procedure...

if InvFull then
TeleportToBank;

Understand? ;)


Yes :)

KeepBotting

2013-01-28 20:07:14

Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;

Ian

2013-01-28 20:15:05

From: KeepBotting
Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;


Like multiple people already told rjj95, there is no reason to have this as a function if he doesn't need it to return anything.

rj

2013-01-28 21:26:35

From: KeepBotting
Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;


Would result in a error.

KeepBotting

2013-01-28 21:29:53

From: rjj95
Would result in a error.


Make it a procedure then so it doesn't have to return anything? It's what I do with my progress reports.

rj

2013-01-28 21:34:18

From: KeepBotting
Make it a procedure then so it doesn't have to return anything? It's what I do with my progress reports.



I did.

KeepBotting

2013-01-28 21:35:30

From: rjj95
I did.

Oh okay. Lol.

ryalf74

2013-01-28 22:17:50

I'm also having the same problem as the TS. Some of the tips helped me. thanks!

Kyle Undefined

2013-01-28 22:29:16

From: KeepBotting
Just make it function WriteDebug(); inetead of function WriteDebug(): boolean;


instead*