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: 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 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 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: 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