Page 1 of 1

Global Variable

Posted: Fri Nov 09, 2007 10:53 pm
by creekmonkey
I need to store a global variable that can be refrenced from all pawn scripts.

I have pawns that respawn. Each has its own script.
After each pawn is killed x number of times it is removed.

What I want is to count the number of times the pawns are killed, and if its more than the global variable, activate a trigger. I have searched the forum and ebook and manual with no luck.

I tried making a variable in player.ini

[dc]
initial = 0
low = 0
high = 10

And in each of the pawn scripts Death order I have

Death[()
{

//DelTimerOrder(1); // remove alert timer
//AddPainOrder("IdlePain", 0); // remove pain order
//FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE); // remove target finding
//DelTriggerOrder("IdleToAlert"); // remove alert trigger
//SetNoCollision(); // remove bounding box so there are no collisions with corpse
switch(random(1,4)) // chose between 4 death animations
{
case 1
{
AnimateStop(DIE, DIEHOLD, "");
}
case 2
{
AnimateStop(DIE1, DIEHOLD, "");
}
case 3
{
AnimateStop(DIE2, DIEHOLD, "");
}
case 4
{
AnimateStop(DIE, DIEHOLD, "");
}
}





PC=PC+1;


PlayerDistOrder(0,"");
FadeOut(DIEFADE,0);



switch(random(1,4)) // chose between 4 death animations
{
case 1
{
TeleportToPoint("p7",0,0,0);
NewPoint("p7");
RotateToAlign("idle",500,false,"");
}
case 2
{
TeleportToPoint("p5",0,0,0);
NewPoint("p5");
RotateToAlign("idle",500,false,"");
}
case 3
{
TeleportToPoint("p8",0,0,0);
NewPoint("p8");
RotateToAlign("idle",500,false,"");
}
case 4
{
TeleportToPoint("p9",0,0,0);
NewPoint("p9");
RotateToAlign("idle",500,false,"");
}
}

if(PC<1)
{

DC=DC+1;

FadeIn(DIEFADE,255);
AttributeOrder("enemy_health",20, "Death"); //eh 50, death
NewOrder("LostTarget");

}

else
{
LowLevel("trig");
}
}]

trig[()
{

if(DC > 2 )
{
ActivateTrigger("doortrig1");
}

HighLevel("Die1");
}]

Die1[()
{

Remove(true);

}]

Everything works fine except the global variable.
Ive tried several variations with no luck, any help os apriciated!!

Re: Global Variable

Posted: Sat Nov 10, 2007 5:32 pm
by Jay
Pawn variables are different from player attributes. Player attributes are global, and are saved, pawn variables are not. To access player attributes you must use the SetAttribute(), GetAttribute() and ModifyAttribute() pawn commands. The last parameter has to be "Player" (this tells rf you want the players attributes, as any pawn or staticentityproxy can have attributes)

So for example:

ModifyAttribute("dc",1,"Player"); //adds 1 to the player attribute 'dc'
SetAttribute("dc",10,"Player"); //sets the player attribute 'dc' to the value 10
PAWNVARIABLE=GetAttribute("dc","Player"); //the value of PAWNVARIABLE will become the value of the player attribute 'dc'

There is plenty of information in the docs that came with RF.