Page 1 of 1

Global Variable

Posted: Mon Jul 23, 2007 2:07 am
by Jaguar_jwg
Can I have a global variable that affects all the pawn scripts?
For example, suppose I wanted a pawn to move if BUTTON = “A”, and a next pawn to move if BUTTON = “B”, and so on.
This information is in a script that allows me to select the ‘buttons’ using the mouse. The pawns are activated individually depending on the button pressed.
Each pawn has its own script because their gravity is different.
Any information on this will be appreciated.

Posted: Mon Jul 23, 2007 2:47 am
by darksmaster923
technially you can use the get attribute cmd
you can get attributes from other pawns
or set it in player.ini

Posted: Mon Jul 23, 2007 7:12 am
by Jaguar_jwg
I don’t understand.
How can the GetAttribute command help me?
Could you explain a bit please?

Posted: Mon Jul 23, 2007 8:12 am
by WebsterX37
why not use a trigger within the level, you can control the state of the trigger or maybe two triggers within your pawn scripts
GetEventState(char *Trigger );

Returns the trigger state

Posted: Mon Jul 23, 2007 10:24 am
by Jay
Yes. You can get and modify the variables from one script in another.
With variables i mean these (they are defined at the beginning of the script):

BUTTON [A] //for example

Lets say the pawn owning the variable Button is named Pawn1. Then another pawn Pawn2 can modify Pawn1's variable with 'calling' Pawn1's name and the variable:

Pawn1.BUTTON = "B";

Now Pawn1's BUTTON variable is B instead of A.

You could just use one of your pawns to store all the global variables and then you modify those when needed.
Attributes have the drawback that they only represent numbers and cannot be strings.

Posted: Mon Jul 23, 2007 7:26 pm
by WebsterX37
cool ... has this trick with the dot: Pawn.Variable been posted somewhere before or is it within the manual?

Posted: Tue Jul 24, 2007 4:23 am
by Jaguar_jwg
I think I am doing everything as you mentioned Jay, but nothing is happening. It's not working.

In the script for Pawn3 I have the variable: ACTION = "test";
I also have: ShowText(3, "", "", ""#ACTION#"", FONT, "", 240, 60, "center", 255);
The text "test" shows up on the screen.

In the script for Pawn1 I have:
if(self.lbutton_pressed)
{
Pawn3.ACTION = "Pass";
}
The text does not change. Am I missing something. If I am could you write the script for me using the above outline? Thanks

Posted: Tue Jul 24, 2007 5:23 pm
by Jay
Do you draw the text every frame (ShowText holds the text i think if you don't change it)? Does it give you any errors? Try Console(true) to check if you have any errors.

If not, could you post both scripts please?

Posted: Tue Jul 24, 2007 6:03 pm
by Jaguar_jwg
I get an error: Field Pawn3 not found
Pawn 3 does exist though.

Here is the script for Pawn3:
{

FONT [10]

Spawn[()
{
Console(true);
HideFromRadar(true);
Gravity(false);
LowLevel("SelectEntityByMouse");
}]

SelectEntityByMouse[()
{
SW = GetScreenWidth(); // ScreenWidth
SH = GetScreenHeight(); // ScreenHeight
ACTION = "test";
NAME = MouseSelect(true, false, 255,255,255,
255,255,255);

if(NAME = "")
{
ShowText(1, "", "", "Nothing Selected", FONT, "",
SW/(2), 100, "center", 255);
}
else
{
ShowText(1, "", "", "This is "#NAME#".",FONT,
"", SW/(2), 150, "center", 255);
}

ShowText(2, "Object1", "", "Box", FONT, "", 0, -30,
"center", 255);
ShowText(3, "", "", ""#ACTION#"", FONT, "", SW/(2),
60, "center", 255);

if((self.lbutton_pressed) and (NAME = " Object1"))
{
for AA = 1 to 32
{
RemoveText(2);
}
ShowText(2, " Object1", "", "Box", FONT, "", 0, -30, "center",
255);

PlayAnimation("", true, "");
RestartOrder();
}
}]

}

Here is the Pawn1 script:
{

// This script creates the menu bar at the top of the screen
POSX [0] // Left top corner X value where the background starts
WIDTH [32] // width of pictures used to build the inventory
NUMPICX [26] // Max number of pictures in the X direction
SPACINGX [0] // spacing between 2 pictures or from the backgound boarder in the X direction
SPACINGY [0] // spacing between boarder and the pictures in the Y direction
TPOSX [280] // X_Position of the menu text string
TPOSY [10] // Y_Position of the menu text string
FONT [10]
FONT1 [13]

// ----------------------------------------------------------------------
// Do not touch the settings for the variables below
MPOSX [0.0] // temporary variable
IPOSX [0] // temporary variable
CHOICE [0] // the number of the selected item

// ----------------------------------------------------------------------
// Do not touch the settings for the variables below
M [8] // temporary variable
I [8] // temporary variable
K [0] // temporary variable
L [1] // temporary variable
SW [0] // ScreenWidth
SH [0] // ScreenHeight
MEM [0] //used to make a toggle button

Spawn[()
{
Console(true);
MouseControlledPlayer(false);
SetKeyPause(false);
SetHudDraw(false);
LowLevel("InitMenu");
}]


InitMenu[()
{
BUTTON = "";
ShowText(10, "", "", ""#BUTTON#"", FONT, "my_sounds\\testing.wav", SW/(2), 40, "center", 255);
SW = GetScreenWidth(); // ScreenWidth
SH = GetScreenHeight(); // ScreenHeight
ShowMouse(true);
self.think = "ShowMenu";
}]

ShowMenu[()
{
//Check if we need to activate the top-menu
if((GetMousePosY()<65) and (GetMousePosY()>0))
{
//Remove all buttons
for MYPIC=1 to NUMPICX+1
{ ShowHudPicture(MYPIC, false); }

//Show Menu background
ShowHudPicture(0, true, "", 0, 0, 0);

//Calculate the active button
MPOSX = ((GetMousePosX()-POSX)/(SPACINGX+WIDTH));
IPOSX = Integer(MPOSX);

if((MPOSX-IPOSX)>(SPACINGX/(SPACINGX+WIDTH)) and (IPOSX<NUMPICX) and (IPOSX>-1))
{
ShowHudPicture((IPOSX+1), true, "", POSX+SPACINGX+IPOSX*(SPACINGX+WIDTH), 0, 0);
self.think="MenuOption" # IPOSX;
}
else
{
//remove text
RemoveText(0);
self.think="ShowMenu";
}
}
else
{
//remove pictures + text
for MYPIC=0 to NUMPICX+1
{ ShowHudPicture(MYPIC, false); }

RemoveText(0);
self.think="ShowMenu";
}
}]

MenuOption0[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "OK", FONT, "", SW/(2), SH/(2), "center", 255);
BUTTON = "A";
ShowText(10, "", "", ""#BUTTON#"", FONT1, "my_sounds\\testing.wav", SW/(2), 40, "center", 255);
Pawn3.ACTION = "Pass";
}
else
{
ShowText(0, "", "", "Use the left mouse button to test.", FONT, "", SW/(2), SH/(2), "center", 255);
}
self.think="ShowMenu";
}]

MenuOption1[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "OK", FONT, "", SW/(2), SH/(2), "center", 255);
}
else
{
ShowText(0, "", "", "Use the left mouse button to test.", FONT, "", SW/(2), SH/(2), "center", 255);
}
self.think="ShowMenu";
}]

MenuOption2[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "OK", FONT, "", SW/(2), SH/(2), "center", 255);
}
else
{
ShowText(0, "", "", "Use the left mouse button to test.", FONT, "", SW/(2), SH/(2), "center", 255);
}
self.think="ShowMenu";
}]

MenuOption3[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "OK", FONT, "", SW/(2), SH/(2), "center", 255);
}
else
{
ShowText(0, "", "", "Use the left mouse button to test.", FONT, "", SW/(2), SH/(2), "center", 255);
}
self.think="ShowMenu";
}]
}

Posted: Tue Jul 24, 2007 8:42 pm
by zany_001
next time put it in code markers pliz,easier to read.

Posted: Tue Jul 24, 2007 10:53 pm
by Jay
are you sure the szEntityName of the Pawn whose variable you want to modify is "Pawn3"? It looks for the szEntityName of the Pawns.

Also, you didn't define the variable ACTION at the top of the script. If you define a variable in an order it might work that you can use the variable in the script itself, but after the order is finished the variable will get deletetd.

You must define it at the top of the script with

ACTION [test]

then it should work. Variables that are declared like this always count for the whole script.

Posted: Wed Jul 25, 2007 5:06 am
by Jaguar_jwg
Thanks Jay, I try that out.
Sorry Zany..., I thought about doing that but forgot.

Posted: Thu Jul 26, 2007 9:59 pm
by Jaguar_jwg
The error has moved, but nothing happens. Do I have to change any part of the scripts in order for the variable to show up as "pass" on the screen?

Posted: Mon Sep 10, 2007 12:24 am
by Markman
It looks like you are overwriting the variable "ACTION" continiously in the first script as the order is looping.
So when you changed it in the second script it is instantaneously changed back to the first value.

You have to define and init the variable in the HEADER. You can also init it in a order that is before the Mainloop-order.

Regards, Markman