global variables
-
- Posts: 51
- Joined: Fri Jul 08, 2005 1:31 pm
- Location: India
global variables
how can I define global variables for a pawn that can be accessed by other pawns?
There are several method.
1. You can use the LevelController entity.
I use a different way. You can see my scripts in my demos to see this in action.
2a. The first method is to use the SetAttribute("YourAttribute", <value>); in your script. You have to declare this Attribute in the Player.ini in the "install" folder.
for example:
Primary script
2b. Another way is to use the SetEventState("YourTrigger", <true or false value>); I prefer this method is much faster than SetAttribute. You don't have to create in the Level Editor a Trigger Entity. The SetEventState automatically creates the entity. For example, if you want to spawn a Spout entity, you don't have to create a Trigger Entity called, for example, "spout_on"; simply put in the right place of you script the SetEventState("spout_on", true); command (and eventually the SetEventState("spout_on", false);) and the Spou entity will turn on.
You can obtain the value using the GetEventState("YourTrigger")
for example:
Primary script
1. You can use the LevelController entity.
I never used it sriously, see the online docs...LevelController Scripting
There can be multiple level controllers in a script, each sharing the same script. (Pawns do not share their script. The Level Controller Entity does.) They can each have their own Start orders and can share global variables within the script. Level Controller scripts always run at a Low Level.
I use a different way. You can see my scripts in my demos to see this in action.
2a. The first method is to use the SetAttribute("YourAttribute", <value>); in your script. You have to declare this Attribute in the Player.ini in the "install" folder.
then the other scripts can obtain the value using the command GetAttribute("YourAttribute")[YourAttribute]
initial = <initial value>
low = <minimum value>
high = <maximum value>
for example:
Primary script
Secondary scriptSetAttribute("YourAttribute", 1);
orif(GetAttribute("YourAttribute")=10)
{
do something;
}
note that the GetAttribute command is influenced by the self.ThinkTime variable. So if self.ThinkTime=0.1; then the script will read the Attribute 10x times in a second; if self.ThinkTime isn't set the GetAttribute command will be executed every frame influencing all the script execution because this is a red/write operation of the engine: it reads directly the file attribute.txt in your RF root folder.TORQUEFORCE=GetAttribute("YourAttribute");
2b. Another way is to use the SetEventState("YourTrigger", <true or false value>); I prefer this method is much faster than SetAttribute. You don't have to create in the Level Editor a Trigger Entity. The SetEventState automatically creates the entity. For example, if you want to spawn a Spout entity, you don't have to create a Trigger Entity called, for example, "spout_on"; simply put in the right place of you script the SetEventState("spout_on", true); command (and eventually the SetEventState("spout_on", false);) and the Spou entity will turn on.
You can obtain the value using the GetEventState("YourTrigger")
for example:
this is a faster way to share an input between different pawns and scripts. Otherwise if you need to share numerical value you have to use the SetAttribute command. Remember that it works only with integer values. So if you want to share the variable APPLE=0.001 you have to do something like this:if(GetEventState("YourTrigger")=true)
{
do something;
}
Primary script
Secondary scriptAPPLE=0.001;
SetAttribute("MyApple", APPLE*10000);
As I said, this command slows down all the scripts esecution. You probably should control it in some way. For example, in my tocco.s script in my Ping!DEMO1.3b (you can found it in my download page) I placed all the SetAttribute GetAttribute commands in a "one shot" Order. When one of the players set a point or makes a fault, the script execute an order (2 second of time is enough...) that manages the Attributes and the Triggers.APPLE=(GetAttribute("MyApple"))/10000;
I hope this explains...RunPlayer_Game[()
{
// aggiungere controllo game + mantieni attributi
debug(GetAttribute("Ai_Game"));
debug(GetAttribute("Player_Game"));
if(((GetEventState("Win_Player")=true)or(GetEventState("Win_Player2")=true))and(PLAYER_GAME!=2))
{
SetAttribute("Player_Game", PLAYER_GAME+1);
}
if(((GetEventState("Win_Player")=true)or(GetEventState("Win_Player2")=true))and(((PLAYER_GAME=2)and(AI_GAME=2))or((PLAYER_GAME=1)and(AI_GAME<1))))
{
SetAttribute("Player_Game", PLAYER_GAME+1);
SetEventState("Win_Player2", true);
SetEventState("Win_Player", false);
}
if(((GetEventState("Win_Ai")=true)or(GetEventState("Win_Ai2")=true))and(AI_GAME!=2))
{
SetAttribute("Ai_Game", AI_GAME+1);
}
if(((GetEventState("Win_Ai")=true)or(GetEventState("Win_Ai2")=true))and(((AI_GAME=2)and(PLAYER_GAME=2))or((AI_GAME=1)and(PLAYER_GAME<1))))
{
SetAttribute("Ai_Game", AI_GAME+1);
SetEventState("Win_Ai2", true);
SetEventState("Win_Ai", false);
}
if(self.time>TIME+2)
{
SetEventState("Adv_Player", false);
SetEventState("Adv_Ai", false);
SetAttribute("Ai_Points",0);
SetAttribute("Player_Points",0);
SetEventState("Win_Player", false);
SetEventState("Win_Ai", false);
SetEventState("AI_Pos",true);//TeleportEntity("AI", "Ai_Start");
TeleportEntity("PLAYER", "Player_Start");
self.think="RunPlayer";
return 0;
}
}
}]
As of the new RF you can completely avoid the attributre system and use the new simkin features to do some SERIOUS data manipulation between pawns....
1 - At the top of your script define whatever variable you want to change. For example: HITPOINTS[10]
2 - Give the pawn an szEntityName. For example: pawn01
3 - The variable for that pawn can be accessed using the convention: pawn01.HITPOINTS and be accessible from any other script.
HP = pawn01.HITPOINTS; // get value
pawn01.HITPOINTS = 5; // set value
You can do this with strings, integers and floats.
1 - At the top of your script define whatever variable you want to change. For example: HITPOINTS[10]
2 - Give the pawn an szEntityName. For example: pawn01
3 - The variable for that pawn can be accessed using the convention: pawn01.HITPOINTS and be accessible from any other script.
HP = pawn01.HITPOINTS; // get value
pawn01.HITPOINTS = 5; // set value
You can do this with strings, integers and floats.
-
- Posts: 51
- Joined: Fri Jul 08, 2005 1:31 pm
- Location: India
>>It's time to tell the truth<<
RF is an amazing creation that really had good intentions right from the start. In case anyone is wondering, officially, RF was first created to prototype 3d shooters. Thanks to guys like Quest and Dairyman, it became the powerful and versatile engine that it is today. RF really is the fastest way to prototype a game.
But times have changed....
The engine that me and a few others have been working on for the past few months has nothing to do with RF and will not be affiliated with it. At the moment, it is unoffically named the FreeVector Engine, but that is most likely to change.
Here is what to expect from it and this is all I will say until the first game with it is released.
1 - It works exactly like RF in the sense that it is a single executable that uses a world, scripts and config files to create the game.
2 - The media will be securely kept within a 'pack' file.
3 - You must create your own shaders using Rendermonkey or another FX capable shader designer tool.
4 - A single, centralized tool is used for all aspects of development.
5 - Supports 3ds, ms3d, X and it's own animation data so that you can create yor own exporters.
6 - It will be free.
7 - It will not be open source.
8 - For Windows platform only.
That's all I'll say. But you will hear more about it with the commercial release of Kumajutso, which will be used to promote the engine.
RF is an amazing creation that really had good intentions right from the start. In case anyone is wondering, officially, RF was first created to prototype 3d shooters. Thanks to guys like Quest and Dairyman, it became the powerful and versatile engine that it is today. RF really is the fastest way to prototype a game.
But times have changed....
The engine that me and a few others have been working on for the past few months has nothing to do with RF and will not be affiliated with it. At the moment, it is unoffically named the FreeVector Engine, but that is most likely to change.
Here is what to expect from it and this is all I will say until the first game with it is released.
1 - It works exactly like RF in the sense that it is a single executable that uses a world, scripts and config files to create the game.
2 - The media will be securely kept within a 'pack' file.
3 - You must create your own shaders using Rendermonkey or another FX capable shader designer tool.
4 - A single, centralized tool is used for all aspects of development.
5 - Supports 3ds, ms3d, X and it's own animation data so that you can create yor own exporters.
6 - It will be free.
7 - It will not be open source.
8 - For Windows platform only.
That's all I'll say. But you will hear more about it with the commercial release of Kumajutso, which will be used to promote the engine.
HEY Dude! long time no see!!!
i thought that was you who posted earlier...
your >>quote<< gave you away :p
your new engine sounds really cool! im sure to check it out can't wait to see the results,
number 6 is very important to me as having limited cash just makes this engine so much more appealling,
tell me one thing though, although it is free are you going to charge if we want to make a commercial release? if so that too is good, as i understand nothing is really for free and you guys should be rewarded for all your labours.
Anyhow how im glad to see your still around dude and best of luck with this new engine it sounds so brilliant!! good luck and hope to see you around in the future..
Ch'e!
i thought that was you who posted earlier...
your >>quote<< gave you away :p
your new engine sounds really cool! im sure to check it out can't wait to see the results,
this combined with your feature list that was posted earlier sounds like this will be an amazing enigne to play around with!1 - It works exactly like RF in the sense that it is a single executable that uses a world, scripts and config files to create the game.
2 - The media will be securely kept within a 'pack' file.
3 - You must create your own shaders using Rendermonkey or another FX capable shader designer tool.
4 - A single, centralized tool is used for all aspects of development.
5 - Supports 3ds, ms3d, X and it's own animation data so that you can create yor own exporters.
6 - It will be free.
7 - It will not be open source.
8 - For Windows platform only.
number 6 is very important to me as having limited cash just makes this engine so much more appealling,
tell me one thing though, although it is free are you going to charge if we want to make a commercial release? if so that too is good, as i understand nothing is really for free and you guys should be rewarded for all your labours.
Awsome so your going to re-release this... er sorry it was a while ago ...did you release this? i remember see-ing screens ect for it can't remember whether this was released or notwith the commercial release of Kumajutso
Anyhow how im glad to see your still around dude and best of luck with this new engine it sounds so brilliant!! good luck and hope to see you around in the future..
Ch'e!
>>if we want to make a commercial release<<
No. The goal is to create a modern tool that is, what RF should have been. I plan on making money from this by, of course, selling a book on how to make games with it. There will however be free tutroials and a complete manual online. However, game design is much more then that, thus the book.
Don't get too excited though folks, this is a huge project in the undertaking and I'm only telling everyone this because it has been working out very well so far. However, it's not a game engine until it creates a game. I'll keep you all posted in the near future.
No. The goal is to create a modern tool that is, what RF should have been. I plan on making money from this by, of course, selling a book on how to make games with it. There will however be free tutroials and a complete manual online. However, game design is much more then that, thus the book.
Don't get too excited though folks, this is a huge project in the undertaking and I'm only telling everyone this because it has been working out very well so far. However, it's not a game engine until it creates a game. I'll keep you all posted in the near future.