From: beginner5
This ?
program new;
var
a ,b ,c : integer;
begin
a := 10;
b := 5;
c := 15;
case a of
0: writeln('df');
b..c : writeln('d');
end;
end.
You can't add options to case statement dynamically inside program. But you can do the same in few other ways. It would be simplier if you say exactly what you want to do.
Yeah, that was pretty much what I meant, you can't have a dynamic case statement can you?
From: J J
You don't have an X amount of TPA's. A TPA is a TPointArray and FindColors will result an Array of TPoints. This means you have an X amount of TPoints. Every TPoint matches the color on the screen that you are searching for.
When you are standing in the flax field you will have multiple flax plants. You use FindColors to make a TPA.
WriteLn(''+ToStr(TPA)+'');
That gives you all the points eg.
Point(100, 100);
Point(105, 110);
Now if you want to randomly pick one of the flaxes you can do something similiar to this (Taken from my barbarian outpost development blog)
if (RopeLength[0] < 100) and (RopeLength[1] < 100) then
begin
case Random(4) of
0: begin
P := RandomRange(Low(SwingClSplit[0]), High(SwingClSplit[0]));
MMouse(SwingClSplit[0][P].X, SwingClSplit[0][P].Y, 0, 0); // Random spot on rope 1
end;
This is actually an array of splitted TPA so an ATPA (Array of TPointArray) aka Array of Array of TPoint
It will randomly click on one of the TPoints in the ATPA. Let me know if this is what you are looking to learn otherwise I will just be typing way too much xD
When I said TPA's, I meant like after they were split up into an ATPA, there are several TPA's in there :P but I was more looking for a dynamic switch statement.
From: Chris
That would be done like:
var Participants: TStringArray;
i: integer;
begin
for i :=0 to high(Participants) do
case lowercase(Participants[i]) of
'bart': MessageHim('hey Bart, ')
'susan': MessageHim('hi mom..')
'lois': MessageHim('Hey <3')
'mark': MessageHim('yo mark, you joint anyways?')
'noob': MessageHim('wow your name is noob? awesome.')
end;
If for example Bart didnt join, he wont get the message.
These are customized messages for each person, I hope this explains something you want to know because Im not sure if this is what your asking for
From: putonajonny
Yes that would work, let's take your lottery idea, you would have everybody pick 5 numbers, at the end of it you want to email everybody saying how many numbers they got right:
program new;
Var
NumberCorrect : array of integer;
Messages : array of String;
i : integer;
begin
//The first person got 4 right, the next got 0 etc...
NumberCorrect := [4, 0, 3, 2, 2, 5, 3];//This array could be any length (dependant on the number of people in your lottery)
Messages := ['Sorry you didn''t get any right, better luck next time', //your messages dependant on the number correct
'You only got 1 number correct, sorry',
'You managed to get 2 correct, well done',
'You got 3 correct and won £20, well done',
'You got 4 numbers correct and won £200, well done',
'You won the jackpot!!!!'];
for i := 0 to high(NumberCorrect) do //for each person it prints out their result
WriteLn('Person '+IntToStr(i)+' - '+Messages[NumberCorrect[i]]);
end.
Compiled successfully in 31 ms.
Person 0 - You got 4 numbers correct and won £200, well done
Person 1 - Sorry you didn't get any right, better luck next time
Person 2 - You got 3 correct and won £20, well done
Person 3 - You managed to get 2 correct, well done
Person 4 - You managed to get 2 correct, well done
Person 5 - You won the jackpot!!!!
Person 6 - You got 3 correct and won £20, well done
Successfully executed.
That's an interesting idea, although it's still not quite dynamic :/