SRL Archive - Reflection Help

R_ChooseOptionMulti


blackfire553

2011-06-25 20:28:44

what is wrong with this?:

Players[0].Arrays[0]:= ['Iron arrow','Bronze arrow'];//items to pick up
if R_ChooseOptionMulti(TStringArray(Players[0].Arrays[0])) then
begin
writeln('Picking some shit up');
writeln(inttostr(ItemPoints[i].x-MyPoint.x) + ' ' + inttostr(ItemPoints[i].y-MyPoint.y));
wait(2500);
itemsPickedUp := itemsPickedUp + 1;
break;
end

This works:

var
ItemsToPickup : TStringArray;

ItemsToPickup := ['Iron arrow','Bronze arrow'];//items to pick up

if R_ChooseOptionMulti(ItemsToPickup) then

Dgby714

2011-06-25 20:40:14

I told you on IRC, TVariantArray <> TStringArray…

Casting should have worked? But it didn't.

blackfire553

2011-06-25 21:20:48

From: Dgby714
I told you on IRC, TVariantArray <> TStringArray…

Casting should have worked? But it didn't.


Sorry, did try that but i deleted the code when i made the workaround. I forgot it because i never got it to work.
I'm just gonna make it two separate arrays so i can get all the item ids in an array also.

Is it possible to cast a TVariantArray into a TStringArray?

Smarter Child

2011-06-25 23:48:27

From: blackfire553
Sorry, did try that but i deleted the code when i made the workaround. I forgot it because i never got it to work.
I'm just gonna make it two separate arrays so i can get all the item ids in an array also.

Is it possible to cast a TVariantArray into a TStringArray?


What exactly do you mean?

Although, you answers might be found in SRL/SRL/Misc/ArrayLoader.scar

{*******************************************************************************
function intArrayToStrEx(intArray: TIntegerArray; Separater: string): string;
By: moparisthebest and modified by Ron
Description: Loads an array of integer into a String. (Example String: '567 389 3234 98342 7998767')
*******************************************************************************}
function intArrayToStrEx(intArray: TIntegerArray; Separater: string): string;
var
i, arrayLength: Integer;
begin
Result := '';
arrayLength := Length(intArray);
repeat
Result := Result + IntToStr(intArray[i]);
if (not (i = (arrayLength - 1))) then
Result := Result + Separater;
Inc(i);
until (i = arrayLength)
end;

{*******************************************************************************
function strToIntArrayEx(intArray, Separater: string): TIntegerArray;
By: moparisthebest, modified by Ron
Description: Loads a String into an array of integer. (Example String: '567 389 3234 98342 7998767')
*******************************************************************************}
function strToIntArrayEx(intArray, Separater: string): TIntegerArray;
var
i, spacePos: Integer;
begin
repeat
SetArrayLength(Result, i + 1);
spacePos := Pos(Separater, intArray);
if (not (spacePos = 0)) then
Result[i] := StrToInt(Copy(intArray, 1, spacePos - 1))
else
begin
Result[i] := StrToInt(Copy(intArray, 1, Length(intArray)));
break;
end;
Delete(intArray, 1, spacePos);
Inc(i);
until (False)
end;

There's no TVariantArray loader in there, but if you load your arrays as a TStringArray or a TIntegerArray, you can convert them vice versa.