Global Variable

Topics regarding Scripting with Reality Factory
Post Reply
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Global Variable

Post 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.
All things you want men to do to you, you also must likewise do to them.
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Post by darksmaster923 »

technially you can use the get attribute cmd
you can get attributes from other pawns
or set it in player.ini
Herp derp.
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Post by Jaguar_jwg »

I don’t understand.
How can the GetAttribute command help me?
Could you explain a bit please?
All things you want men to do to you, you also must likewise do to them.
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

Post 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
At the long run we are all dead.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
WebsterX37
Posts: 16
Joined: Sat Jul 07, 2007 4:44 pm
Location: Berlin, Germany

Post by WebsterX37 »

cool ... has this trick with the dot: Pawn.Variable been posted somewhere before or is it within the manual?
At the long run we are all dead.
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Post 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
All things you want men to do to you, you also must likewise do to them.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post 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?
Everyone can see the difficult, but only the wise can see the simple.
-----
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Post 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";
}]
}
All things you want men to do to you, you also must likewise do to them.
User avatar
zany_001
Posts: 1047
Joined: Fri Mar 02, 2007 8:36 am
Location: Aotearoa

Post by zany_001 »

next time put it in code markers pliz,easier to read.
Once I was sad, and I stopped being sad and was awesome instead.
True story.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Post by Jaguar_jwg »

Thanks Jay, I try that out.
Sorry Zany..., I thought about doing that but forgot.
All things you want men to do to you, you also must likewise do to them.
Jaguar_jwg
Posts: 96
Joined: Sun May 20, 2007 7:47 am

Post 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?
All things you want men to do to you, you also must likewise do to them.
User avatar
Markman
Posts: 21
Joined: Sat Jan 14, 2006 2:28 pm

Post 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
Post Reply