Author Topic: String to Variable?  (Read 799 times)

0 Members and 1 Guest are viewing this topic.

Offline DevilX4

  • Major(1)
  • Posts: 30
String to Variable?
« on: December 24, 2011, 05:54:40 am »
Hi all, I was wondering if there was any way to read from a string and use that string in a part of a variable.

Heres the basic code using 'skill' as an example:
Code: [Select]
procedure SkillInfoz(ID: byte; skillz: string);
begin
writeconsole(ID,'Your skill '+skillz+' is at level '+inttostr(players[ID].+skillz+)+' !',CYellow);
end;

function OnPlayerCommand(ID: byte; text: string): boolean;
begin
if (getpiece(text,' ',0) = '/skill') AND (getpiece(text,' ',1) <> nil) then SkillInfoz(ID,GetPiece(Text, ' ', 1));
end;
I thought that maybe using the +'s like you do with a string would work, but it doesn't.

Any ideas?

Thanks.
« Last Edit: December 24, 2011, 05:56:43 am by DevilX4 »

Offline SyavX

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 338
Re: String to Variable?
« Reply #1 on: December 24, 2011, 06:37:20 am »
Code: [Select]
procedure SkillInfoz(ID: byte; skillz: string);
var tmp: integer;
begin
case lowercase(skillz) of
  'skill01': tmp := players[ID].skill_one;
  'skill02': tmp := players[ID].skill_two;
  'skill03': tmp := players[ID].skill_three;
else
  tmp := -32768;
end;

if tmp <> -32768 then writeconsole(ID,'Your skill '+skillz+' is at level '+inttostr(tmp)+' !',CYellow);
end;

function OnPlayerCommand(ID: byte; text: string): boolean;
begin
if (lowercase(getpiece(text,' ',0)) = '/skill') AND (getpiece(text,' ',1) <> nil) then SkillInfoz(ID,GetPiece(Text, ' ', 1));
end;
« Last Edit: December 24, 2011, 06:54:17 am by SyavX »

Offline DevilX4

  • Major(1)
  • Posts: 30
Re: String to Variable?
« Reply #2 on: December 24, 2011, 02:10:17 pm »
Thanks very much for you help SyavX.  Worked a treat.