global variables

Topics regarding Scripting with Reality Factory
Gamespider
Posts: 51
Joined: Fri Jul 08, 2005 1:31 pm
Location: India

global variables

Post by Gamespider » Sat Aug 06, 2005 9:26 am

how can I define global variables for a pawn that can be accessed by other pawns?

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Sat Aug 06, 2005 1:14 pm

There are several method.
1. You can use the LevelController entity.
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 never used it sriously, see the online docs... :wink:

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.
[YourAttribute]
initial = <initial value>
low = <minimum value>
high = <maximum value>
then the other scripts can obtain the value using the command GetAttribute("YourAttribute")
for example:
Primary script
SetAttribute("YourAttribute", 1);
Secondary script
if(GetAttribute("YourAttribute")=10)
{
do something;
}
or
TORQUEFORCE=GetAttribute("YourAttribute");
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.

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:
if(GetEventState("YourTrigger")=true)
{
do something;
}
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:
Primary script
APPLE=0.001;
SetAttribute("MyApple", APPLE*10000);
Secondary script
APPLE=(GetAttribute("MyApple"))/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.
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;
}
}
}]
I hope this explains...

Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout » Sat Aug 06, 2005 5:40 pm

I've added this a while ago and will be part of the new release
Any global variable defined in any script is then readable/changable by any other script
The new release also enables you to save and load these globals in a file using a script command

Guest

Post by Guest » Sat Aug 06, 2005 5:53 pm

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.

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Sat Aug 06, 2005 8:29 pm

Oh! :D

Welcolme Back Pickle!!!

I discover you! :lol:
you're right, this is the right way to do it!
Ciao amico, torna a partecipare al forum!!!

Guest

Post by Guest » Sat Aug 06, 2005 10:27 pm

Hey federico bello! How's things? I'm just stopping by here and there. Good to see you're still making great demos though! Keep up the aweswome work!

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Mon Aug 08, 2005 12:12 am

Hey Guys Listen!!! This is a Great Man!!! 8)
All we are really curious about your mysterious words about an RF 2.0 project... :wink: It's time to tell the truth!

Guest

Post by Guest » Mon Aug 08, 2005 1:52 am

use the new simkin features
Can anyone point me in the right direction or tell me where i can find these features...like a manual or tutorials for simkin, or should i just goto the simkin website? thx in advance

:lol:

Gamespider
Posts: 51
Joined: Fri Jul 08, 2005 1:31 pm
Location: India

Post by Gamespider » Mon Aug 08, 2005 11:25 am

Rf can do that? wow! I never thouht u could do it!

well pickles was that really u? y didnt u logon bfore posting? secetive eh..?

User avatar
Master
Posts: 81
Joined: Tue Jul 12, 2005 6:58 pm
Contact:

Post by Master » Mon Aug 08, 2005 7:01 pm

Simkin is the script that in game pawns use. The docs should have everything you need to know about simkin in the Pawn Scripting section.

Guest

Post by Guest » Mon Aug 08, 2005 9:51 pm

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

User avatar
Master
Posts: 81
Joined: Tue Jul 12, 2005 6:58 pm
Contact:

Post by Master » Mon Aug 08, 2005 10:27 pm

Can't wait.

User avatar
Spyrewolf
Posts: 450
Joined: Tue Jul 05, 2005 4:53 am
Location: Wellington::New Zealand

Post by Spyrewolf » Tue Aug 09, 2005 4:59 am

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,
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.
this combined with your feature list that was posted earlier sounds like this will be an amazing enigne to play around with!

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.
with the commercial release of Kumajutso
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 not :oops:

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!

Guest

Post by Guest » Tue Aug 09, 2005 7:38 pm

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

User avatar
wiseman2
Posts: 33
Joined: Wed Jul 27, 2005 4:17 am
Location: denver, co
Contact:

Post by wiseman2 » Wed Aug 17, 2005 8:05 am

Hadn't seen you around either...glad you're still popping in on occasion....

will await your book....

Post Reply