SRL Archive - OSR Help

how to: Const values?


okokokok

2013-06-12 07:59:04

Hello guys,

I have one question about the const values in a script.
I have the next procedures (just an example):

program new;
begin

Const

FoodType = Swordfish; //Type of food you will use


procedure SetDTM;
var Lobster, Swordfish, Tuna, Trout, Salmon: Integer;
begin
Swordfish := DTMFromString('mrAAAAHic42BgYLgGxfeB+BEQ3wDiC0B8CojPAfE8IJ4CxNOg7KVAvAKIl0H5AbbWDMH2NgyhTnYMRREhQBFGMJ5UkMUQ4+7CwArk4cOMBDAMAAB8dRG7');
Lobster := DTMFromString('m1gAAAHic42JgYLgBxPeg9CUgPgfEp6BskPgjKH0IiM9C5U8A8TGo2H4g3gLE24D4CBAvd+MAkowMW3y5wOxDQVwMHOzsDHOcOBiqTdgZtvtxgdmsQFXEYEYiMQIAAENQGAQ=');
Tuna := DTMFromString('mwQAAAHic42RgYLgGxY+A+AkQ34byTwHxGSC+AMQvgfgBEN+BqnsFxB+A+BMQvwHiF0B8SJeLIcpIC8hihOPZIR4Mx0vTGKYoczAUSLIzsAJFCWFGIjAcAADJdxXK');
Trout := DTMFromString('mrAAAAHic42BgYLgOxNeA+B4QPwHiB0B8BYhPAPElIGZnZGBgAmI2IOYFYgEg5gNiCSDmAOIwsxgGL9UgoEpGBj/1UIYutxkMc/xXMbQ4T2BIsE1nYAXK4MOMBDAMAADwKQ8k');
Salmon := DTMFromString('m1gAAAHic42JgYLgGxQ+A+BEQ3wHiG0B8BYjPAfEZIL4AxGaMDAx6QKwFpU2A2BKIbYDYDoitGCFqckMCGKz1dBjCXRwZ4j3dGFrTEoG6GRmq46MY5lYWMYT4+jL4WJkzsAJFicGMRGIEAACVVRPo');
end;

Procedure FreeDTM;
var Lobster, Swordfish, Tuna, Trout, Salmon: Integer;
begin
FreeDTM(Swordfish);
FreeDTM(Lobster);
FreeDTM(Tuna);
FreeDTM(Salmon);
FreeDTM(Trout);
end;

Procedure Eat;
var Lobster, Swordfish, Tuna, Trout, Salmon,x,y: Integer;
begin

if FindDTM('OneOfThoseDTMS',x,y,MIX1,MIY1,MIX2,MIY2) THEN

begin
Writeln('Found Food');
end;
end;

end.

Now my question: How can I integrate FoodType in the procedure "eat"?

Thanks in advance

Awkwardsaw

2013-06-12 08:16:43

You need what's called a case.


const
food = 'swordfish';
procedure eat;
begin

case food of
'swordfish' : writeln('swordfish');
'tuna' : writeln('tuna');
'monkfish' : writeln('monkfish');
'lobster' : writeln('lobster');
end;

end;

There are plenty of tutorials that explain what one is/ how to use them if my example doesn't help :)

okokokok

2013-06-12 08:21:12

Ok thanks!

But would this also work with the DTMs?

So I meant replacing 'OneOfThoseDTMS' in the procedure eat with food or FoodType?

Awkwardsaw

2013-06-12 08:31:51


const
food = 'swordfish';
procedure eat;
begin

case food of
'swordfish' : finddtm(swordfish,.....);
'tuna' : finddtm(tuna,.....);
'monkfish' : finddtm(monkfish,.....);
'lobster' : finddtm(Lobster,.....);
end;

end;

;)

ActualNoob

2013-06-12 08:38:44

yeah thats pretty much how i would do it too heres mine:


Const
FOODTYPE = 'swordfish'; //Type of food you will use

var
FoodDTM : Integer;

procedure SetDTM(const FoodType : String);

begin
case FoodType of
'swordfish' :begin
FoodDTM := DTMFromString('mrAAAAHic42BgYLgGxfeB+BEQ3wDiC0B8CojPAfE8IJ4CxNOg7KVAvAKIl0H5AbbWDMH2NgyhTnYMRREhQBFGMJ5UkMUQ4+7CwArk4cOMBDAMAAB8dRG7');
end;
'lobster': begin
FoodDTM:= DTMFromString('m1gAAAHic42JgYLgBxPeg9CUgPgfEp6BskPgjKH0IiM9C5U8A8TGo2H4g3gLE24D4CBAvd+MAkowMW3y5wOxDQVwMHOzsDHOcOBiqTdgZtvtxgdmsQFXEYEYiMQIAAENQGAQ=');
end;
'tuna': begin
FoodDTM:=DTMFromString('mwQAAAHic42RgYLgGxY+A+AkQ34byTwHxGSC+AMQvgfgBEN+BqnsFxB+A+BMQvwHiF0B8SJeLIcpIC8hihOPZIR4Mx0vTGKYoczAUSLIzsAJFCWFGIjAcAADJdxXK');
end;
'trout': begin
FoodDTM:=DTMFromString('mrAAAAHic42BgYLgOxNeA+B4QPwHiB0B8BYhPAPElIGZnZGBgAmI2IOYFYgEg5gNiCSDmAOIwsxgGL9UgoEpGBj/1UIYutxkMc/xXMbQ4T2BIsE1nYAXK4MOMBDAMAADwKQ8k');
end;
'salmon': begin
FoodDTM:=DTMFromString('m1gAAAHic42JgYLgGxQ+A+BEQ3wHiG0B8BYjPAfEZIL4AxGaMDAx6QKwFpU2A2BKIbYDYDoitGCFqckMCGKz1dBjCXRwZ4j3dGFrTEoG6GRmq46MY5lYWMYT4+jL4WJkzsAJFicGMRGIEAACVVRPo');
end;
end;
end;


Procedure FreeFoodDTM;
begin
FreeDTM(foodDTM);
end;


Procedure Eat;
begin

if FindDTM(foodDTM,x,y,MIX1,MIY1,MIX2,MIY2) THEN

begin
Writeln('Found Food');
end;
end;


or


Const
FOODTYPE = 'swordfish'; //Type of food you will use


Function getFoodDTM(const FoodType : String) : Integer;

begin
case FoodType of
'swordfish' :begin
Result := DTMFromString('mrAAAAHic42BgYLgGxfeB+BEQ3wDiC0B8CojPAfE8IJ4CxNOg7KVAvAKIl0H5AbbWDMH2NgyhTnYMRREhQBFGMJ5UkMUQ4+7CwArk4cOMBDAMAAB8dRG7');
end;
'lobster': begin
Result:= DTMFromString('m1gAAAHic42JgYLgBxPeg9CUgPgfEp6BskPgjKH0IiM9C5U8A8TGo2H4g3gLE24D4CBAvd+MAkowMW3y5wOxDQVwMHOzsDHOcOBiqTdgZtvtxgdmsQFXEYEYiMQIAAENQGAQ=');
end;
'tuna': begin
Result:=DTMFromString('mwQAAAHic42RgYLgGxY+A+AkQ34byTwHxGSC+AMQvgfgBEN+BqnsFxB+A+BMQvwHiF0B8SJeLIcpIC8hihOPZIR4Mx0vTGKYoczAUSLIzsAJFCWFGIjAcAADJdxXK');
end;
'trout': begin
Result:=DTMFromString('mrAAAAHic42BgYLgOxNeA+B4QPwHiB0B8BYhPAPElIGZnZGBgAmI2IOYFYgEg5gNiCSDmAOIwsxgGL9UgoEpGBj/1UIYutxkMc/xXMbQ4T2BIsE1nYAXK4MOMBDAMAADwKQ8k');
end;
'salmon': begin
Result:=DTMFromString('m1gAAAHic42JgYLgGxQ+A+BEQ3wHiG0B8BYjPAfEZIL4AxGaMDAx6QKwFpU2A2BKIbYDYDoitGCFqckMCGKz1dBjCXRwZ4j3dGFrTEoG6GRmq46MY5lYWMYT4+jL4WJkzsAJFicGMRGIEAACVVRPo');
end;
end;
end;


Procedure Eat;
var
foodDTM : Integer;
begin
foodDTM := getFoodDTM(FOODTYPE);
if FindDTM(foodDTM,x,y,MIX1,MIY1,MIX2,MIY2) THEN

begin
Writeln('Found Food');
end;

freeDTM(foodDTM);
end;

okokokok

2013-06-12 09:42:52

Thanks guys!
ButI'm sorry to say, these functions don't work.. :S
Refreshed DTMs etc. I don't get this stuff :P

ActualNoob

2013-06-12 11:11:15

really? i tried the second code snippet and it was working for me. I tested it on some of my desktop icons.

did you use ctrl+d inside the dtm editor to see if it can actually find the different types of food?
did you call the procedure Eat?

okokokok

2013-06-12 12:48:42

Yes, yes and yes :S
When I call determine one of the DTMs in the start of the procedure it works.
But when i don't do that, I'm not able to find them in the inventory. :S

Edit: Maybe i'll just make it support salmon only, since it's a low level script anyway. Sharks and swordfish will probably not be used.

bob_dole

2013-06-12 13:45:34

misread the post. deleted my derp reply.

Could you post the exact code you are using so we can tell you what the issue is.

okokokok

2013-06-18 17:06:23

Found the problem.
You forgot to call setDTM.

Const
FOODTYPE = 'swordfish'; //Type of food you will use

var
FoodDTM : Integer;

procedure SetDTM(const FoodType : String);

begin
case FoodType of
'swordfish' :begin
FoodDTM := DTMFromString('mrAAAAHic42BgYLgGxfeB+BEQ3wDiC0B8CojPAfE8IJ4CxNOg7KVAvAKIl0H5AbbWDMH2NgyhTnYMRREhQBFGMJ5UkMUQ4+7CwArk4cOMBDAMAAB8dRG7');
end;
'lobster': begin
FoodDTM:= DTMFromString('m1gAAAHic42JgYLgBxPeg9CUgPgfEp6BskPgjKH0IiM9C5U8A8TGo2H4g3gLE24D4CBAvd+MAkowMW3y5wOxDQVwMHOzsDHOcOBiqTdgZtvtxgdmsQFXEYEYiMQIAAENQGAQ=');
end;
'tuna': begin
FoodDTM:=DTMFromString('mwQAAAHic42RgYLgGxY+A+AkQ34byTwHxGSC+AMQvgfgBEN+BqnsFxB+A+BMQvwHiF0B8SJeLIcpIC8hihOPZIR4Mx0vTGKYoczAUSLIzsAJFCWFGIjAcAADJdxXK');
end;
'trout': begin
FoodDTM:=DTMFromString('mrAAAAHic42BgYLgOxNeA+B4QPwHiB0B8BYhPAPElIGZnZGBgAmI2IOYFYgEg5gNiCSDmAOIwsxgGL9UgoEpGBj/1UIYutxkMc/xXMbQ4T2BIsE1nYAXK4MOMBDAMAADwKQ8k');
end;
'salmon': begin
FoodDTM:=DTMFromString('m1gAAAHic42JgYLgGxQ+A+BEQ3wHiG0B8BYjPAfEZIL4AxGaMDAx6QKwFpU2A2BKIbYDYDoitGCFqckMCGKz1dBjCXRwZ4j3dGFrTEoG6GRmq46MY5lYWMYT4+jL4WJkzsAJFicGMRGIEAACVVRPo');
end;
end;
end;


Procedure FreeFoodDTM;
begin
FreeDTM(foodDTM);
end;


Procedure Eat;
begin
SetDTM(FoodType);

if FindDTM(foodDTM,x,y,MIX1,MIY1,MIX2,MIY2) THEN

begin
Writeln('Found Food');
end;
end;