SRL Archive - OSR Help

Make a function return two values (Integer and Boolean)


YoHoJo

2012-01-07 00:03:35

Function MineRock(WutRock:Integer):Boolean;  

Got that.
Want it to return the Boolean like it already does, AND an Integer (planning to make it how many rocks with ores it found).
How Do?

Flight

2012-01-07 00:10:57

Function MineRock(WutRock:Integer, var ProducedInt: Integer):Boolean;

:)?

YoHoJo

2012-01-07 00:12:02

Um, so then how would I call/use that elsewhere to find out how many?
Like Writeln(IntToStr(WHAT?!));

Brandon

2012-01-07 00:12:22

How do? What u mean?

Like this?


program new;

type
Custom = record
Bool: boolean;
Int: Integer;
end;


Function LetsReturnTwoValues: Custom;
begin
//Do stuff to get some results/values..
//.................
//.................

//Return two values..
Result.Bool:= True;
Result.Int:= 5035
end;

Procedure AssignTwoValues;
var
TwoVals: Custom; //Notice the Custom type..
begin
//This will Access/Assign the two values.. NOT return..

writeln(TwoVals.Bool);//Accessing

TwoVals.Bool:= False; //Assigning
TwoVals.Int:= 5252352;
end;

YoHoJo

2012-01-07 00:15:18

I don't get the AssignTwoValues :/

Everything above that seems to be what I want though hmmm

Brandon

2012-01-07 00:17:48

It's just a function I made to I guess show you how to access the values you have stored..



//That function above.. has now stored it's results in Bool and Int of the Custom Record right?
//Now lets access those values so we can do stuff with them..

var
Rock: Custom;

begin
writeln(Rock.Bool); //Accessing the values of Rock which is of type custom.. should print true..
Writeln(Rock.Int); //This should print that 5035..
end.

Kyle Undefined

2012-01-07 00:21:13

Based on what you want:


var
ret : Integer;

if(MineRock(ROCK_IRON, ret))then
WriteLn(IntToStr(ret));

However, I'd suggest a Type like ggzz posted.


type
Custom = record
Bool : Boolean;
Int : Integer;
end;

function retValues() : Custom;
begin
with Result do
begin
Bool := True;
Int := 123;
end;
end;

procedure printValues();
var
ret : Custom;
begin
ret := retValues();
WriteLn(BoolToStr(ret.Bool));
WriteLn(IntToStr(ret.Int));
end;

YoHoJo

2012-01-07 00:22:37

How do I do something like
If MineRock(Players[CurrentPlayer].Integers[1]).Bool=True Then

Kyle Undefined

2012-01-07 00:31:45

I'm confused on what you want to accomplish…?

YoHoJo

2012-01-07 00:37:36

I want the function to return TRUE if rock was found/clicked AND I want it to return how many rocks were found.

Like I want to use it like

If MineRock('Iron') Then
Begin
AntiBan;
Sex;
End;

And elsewhere in the script I want to do

If MineRock<5 Then
MoveToAnotherLocation;

Flight

2012-01-07 00:40:56

Something like this?

var
NumFound: Integer;

If MineRock('Iron', NumFound) Then
Begin
AntiBan;
Sex;
End;

An use the NumFound elsewhere? If it's used in multiple places it'll have to be a global variable. I dunno though, I might still be off track as to your request.

Kyle Undefined

2012-01-07 00:42:47


type
TRock = record
Found : Boolean;
HowMany : Integer;
end;

function MineRock(Which : Integer) : TRock;
begin
// Do mining stoof
with Result do
begin
Found := True; // Could be used in a TPA and set True/False depending if it was found
HowMany := 3; // Same idea with TPA, Length(TPA)
end;
end;

procedure MainLoop;
var
pRock : TRock;
begin
pRock := MineRock(ROCK_IRON);
if(pRock.HowMany < 5)then
MoveToAnotherLocation;
end;

Something like that?

Bonfield

2012-01-07 01:19:54

Can you use out?

Er1k

2012-01-07 06:22:47

From: YoHoJo
How do I do something like
If MineRock(Players[CurrentPlayer].Integers[1]).Bool=True Then


This isn't java so I think you must pass your results to a struct first?

result:= MineRock(Players[CurrentPlayer].Integers[1])
if result.bool = true then
;//do whatever you want?

Richard

2012-01-07 07:17:41

Instead of creating a whole new type, surely you could just create a tVariantArray. Would save the messing about with with..dos and all that. Wouldn't really be that complex:

program new;

function returnTwoVals(val1: integer; val2: boolean): tVariantArray;
begin
Result := [val1, val2];
end;

var
tva: tVariantArray;
begin
tva := returnTwoVals(5,true);
writeLN(intToStr(tva[0]) + ', ' + boolToStr(tva[1]));
end.

Bonfield

2012-01-07 07:40:23

You can use out and have the function return two variables, you can have it true for the rock click and also return 8 for the number of found rocks, sorry I can't provide an example if by the time I'm home and remember I will try to post one up

NCDS

2012-01-07 08:46:05

Why is this being so over complicated?

function MineRock(Rock: Integer; var numRock: Integer): Boolean;

When you put 'var' in front of a parameter you can use that variable inside the function and ooutside.

So, with the example I just used:

if MineRock(rock, number) then
Writeln('Found '+toStr(number));

Sir R. M8gic1an

2012-01-07 08:58:07

From: NCDS
Why is this being so over complicated?

function MineRock(Rock: Integer; var numRock: Integer): Boolean;

When you put 'var' in front of a parameter you can use that variable inside the function and ooutside.

So, with the example I just used:

if MineRock(rock, number) then
Writeln('Found '+toStr(number));


this

-RM

YoHoJo

2012-01-10 03:05:56

I'm still lost here, :/.

I have the function MineRock(WutRock:Integer); (Wutrock (1, 2, 3, etc etc) just means iron, coal, tin, etc.

I want to be able to do something like

If MineRock.Boolean Then blalbalbal
AND
WriteLn(IntToStr(MineRock.Integer)));

With the same function.

So, RM and NCDS are saying

if MineRock(rock, number) then
Writeln('Found '+toStr(number));

So um, how would I assign a value to 'number'?
Like let's say I got
FindColorsSpiralTolerance(MSCX,MSCY,OrePts,2434854,SearchBox.x1,SearchBox.y1,SearchBox.x2,SearchBox.y2,10);          

How would I make the number of rocks found, in our case here 'number' := OrePts (OrePts right now ofc is an TPA).

weequ

2012-01-10 04:03:57

Like this?

program new;
type
MineRockInfo = record
Boolean: Boolean;//Might want to change the variable name 'Boolean' to something like 'found'
Integer: Integer;//Might want to change the variable name 'Integer' to something like 'amount'
end;

function MineRock: MineRockInfo;
begin
Result.Boolean := True;
Result.Integer := 5;
end;


begin
Writeln(BoolToStr(MineRock.Boolean));
Writeln(IntToStr(MineRock.Integer));
end.
That would however call the function twice that we don't want.

Here is a better example:

program new;

type
MineRockInfo = record
Boolean: Boolean;//Might want to change the variable name 'Boolean' to something like 'found'
Integer: Integer;//Might want to change the variable name 'Integer' to something like 'amount'
end;

var
MineInfo: MineRockInfo;

function MineRock: MineRockInfo;
begin
Result.Boolean := True;
Result.Integer := 5;
end;


begin
MineInfo := MineRock;//MineRock only being called once!
Writeln(BoolToStr(MineInfo.Boolean));
Writeln(IntToStr(MineInfo.Integer));
end.

YoHoJo

2012-01-10 04:07:45

Thanks for clarification I also talked to Kyle and I think I've gotten it figured out thanks everyone. Plan to release another script in the next few weeks.
Going to be called Dr. Dick.

euphemism

2012-01-10 04:09:42

From: YoHoJo
I'm still lost here, :/.

I have the function MineRock(WutRock:Integer); (Wutrock (1, 2, 3, etc etc) just means iron, coal, tin, etc.

I want to be able to do something like

If MineRock.Boolean Then blalbalbal
AND
WriteLn(IntToStr(MineRock.Integer)));

With the same function.

So, RM and NCDS are saying

if MineRock(rock, number) then
Writeln('Found '+toStr(number));

So um, how would I assign a value to 'number'?
Like let's say I got
FindColorsSpiralTolerance(MSCX,MSCY,OrePts,2434854,SearchBox.x1,SearchBox.y1,SearchBox.x2,SearchBox.y2,10);          

How would I make the number of rocks found, in our case here 'number' := OrePts (OrePts right now ofc is an TPA).


When you place 'var' in front of a parameter, you are letting the function/procedure know that not only are you passing a variable in, but that you are wanting the function/procedure to pass information out through the variable. If you put 'out' in front of a parameter, the function/procedure will ignore the current value of the variable, and will only pass out the modified version of it. So, if we do something like:

Function MineRock(WutRock:Integer; out NumOfRocks):Boolean;

and you then do:


if MineRock(Rock, Number) then

And somewhere in the function you put:


NumOfRocks := Length(OrePts);

Then after the function is through, you'll have the number of returned points stored within 'Number'. If you want to do further stuffz in the function to return just the rocks, you need to remember to set 'NumOfRocks' to that final value.