Author Topic: [Solved]Basic problem.  (Read 841 times)

0 Members and 1 Guest are viewing this topic.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
[Solved]Basic problem.
« on: December 08, 2009, 07:45:09 pm »
Hi again guys, lol.

I work badly in a script, and an error has just popped in my face and it seems like i can't fix it.

I'm not so good explaining so i'm just gonna show you the pieces of script.

Huuh... an exemple :

Code: (pascal) [Select]
var
Random : byte;
SomeoneGotId : boolean;
procedure OnPlayerSpeak(ID: Byte; Text: string)
  begin
   if Text = '!getid' then begin
    Random := ID;
    SomeoneGotId := true;
   end;
   if Text = '!giveid' then begin
    Random := 0;
    SomeoneGotId := false;
  end;
 end;

procedure OnLeaveGame(ID, Team: byte;Kicked: boolean);
 begin
  if (SomeoneGotId = true) and (Random = ID) then begin
    Random := 0;
    SomeoneGotId := false;
  end;
 end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
 begin
  // Test to see who got the Random id
  if Text = '/whogotid' then begin
   WriteConsole(ID, 'Random = ' + IDToName(Random),$FFFF0000);
  end;
end;

Here is the problem. In the other procedures than OnPlayerSpeak, the Random variable is 255 and it displays : Random = Server Admin.

What is the problem ?

Thanks for solving it.

EDIT: FIXED AN ERROR IN THE EXEMPLE
« Last Edit: December 10, 2009, 03:49:33 pm by VinceBros »

Offline Silnikos

  • Soldier
  • **
  • Posts: 129
Re: Basic problem.
« Reply #1 on: December 09, 2009, 01:41:01 am »
Here is the problem. In the other procedures than OnPlayerSpeak, the Random variable is 255 and it displays : Random = Server Admin.

What is the problem ?
255 is server admin's ID, if you use this variable for other functions, rename this one so they won't collide?

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Basic problem.
« Reply #2 on: December 09, 2009, 09:39:30 am »
Try renaming the variable to RandomX(in example..), also you don't need SomeoneGotId, just compare Random with 0.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Basic problem.
« Reply #3 on: December 09, 2009, 03:13:44 pm »
Mmh, you don't see to understand my problem.

The Random Var in OnPlayerSpeak has the value of the ID.
But in the other functions it's the server admin, which should be the ID in OnPlayerSpeak

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Basic problem.
« Reply #4 on: December 09, 2009, 11:59:16 pm »
Maybe first try and then say I'm wrong?

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Basic problem.
« Reply #5 on: December 10, 2009, 03:48:44 pm »
Well my variable name in the script is not Random.
In the exemple, Yes. But i fixed problem :). Thanks anyway.