SRL Archive - OSR Help

Need help....


bud_wis_er_420

2012-01-08 16:04:34

Sry about the vague title, couldn't think of a good title that would explain what I need help with.

I want the variable make[0] to hold 2 strings. the first sting is what to make the second is the amount to make. make[1] would hold another 2 strings of the same type, etc. I then would be able to call the variable make[0].potion or make[0].amount to get the different stings from each array. I am not sure on how exactly to set this up. here is what I have come up with so far.

This should print out:
Super Attack
Super Strength
Super Defence
Attack
program New;
{$i srl/srl.scar}

procedure What_to_Make;
var
//don't know how to do this
Make: TStringArray;
begin
SetArrayLength(Make, 2);

//Fill in what to make
//Make[i].potion Make[i].amount
Make[0] := ('Super Attack', '100');
Make[1] := ('Super Strength', '100');
Make[2] := ('Super Defence', '100');
Make[3] := ('Attack', '100');
end;

Begin
SetupSRL();
for i := 0 to High(Make) do
begin
Writeln(Make[i].potion)

End.

PatDuffy

2012-01-08 16:06:57

The way you have it is storing a String Array in a string array, which I don't think you want to do :p

Why are the '100' needed?

Shuttleu

2012-01-08 16:08:52

something like this
type
Custom = record
Potion: string;
Amount: Integer;
end;

var
Make: array of Custom;

SetArrayLength(Make, 4);
Make[0].Potion := 'Super Attack';
Make[0].Amount := 100;

Make[1].Potion := 'Super Strength';
Make[1].Amount := 100;

Make[2].Potion := 'Super Defence';
Make[2].Amount := 100;

Make[3].Potion := 'Attack';
Make[3].Amount := 100;

~shut

bud_wis_er_420

2012-01-08 16:18:38

From: Shuttleu
something like this
type
Custom = record
Potion: string;
Amount: Integer;
end;

var
Make: array of Custom;

SetArrayLength(Make, 4);
Make[0].Potion := 'Super Attack';
Make[0].Amount := 100;

Make[1].Potion := 'Super Strength';
Make[1].Amount := 100;

Make[2].Potion := 'Super Defence';
Make[2].Amount := 100;

Make[3].Potion := 'Attack';
Make[3].Amount := 100;

~shut


Ok i see. Thx but is there anyway to still use my setup procedure with the above for easier reading of users. What I mean is the I like being able to enter the value of the variable make this way:
Make[0] := ('Super Attack', '100');  
This is what people are gona fill out to tell what pots they wana make until I make a GUI for the script anyways.

…and is there a tut for this
type
Custom = record
Potion: string;
Amount: Integer;
end;
stuff. Never used that before
Edit: nvm found one.

Shuttleu

2012-01-08 16:34:52

you can do this
function SetVars(Potion: string; amount: Integer): Custom;
begin
Result.Potion:= Potion;
Result.Amount:= Amount;
end;

then you can set them like this
  Make[0] := SetVars('Super Attack', 100);

Make[1] := SetVars('Super Strength', 100);

Make[2] := SetVars('Super Defence', 100);

Make[3] := SetVars('Attack', 100);

~shut

bud_wis_er_420

2012-01-08 16:47:54

Thx for the help, but can you give me an actual compilable example, I'm having trouble arranging everything. Thx very much.

At least it compiles. But it don't write the viable out.
program New;
{$i srl/srl.scar}

type
Custom = record
Potion: string;
Amount: Integer;
end;

var
i: integer;
Make: array of Custom;

procedure What_to_Make;
begin
SetArrayLength(Make, 4);
Make[0].Potion := 'Super Attack';
Make[0].Amount := 100;

Make[1].Potion := 'Super Strength';
Make[1].Amount := 100;

Make[2].Potion := 'Super Defence';
Make[2].Amount := 100;

Make[3].Potion := 'Attack';
Make[3].Amount := 100;
end;

Begin
SetupSRL();
What_to_Make;
Writeln(Make[0].potion)
for i := 0 to High(Make) do
begin
Writeln(Make[i].potion)
end;
End.