Accessing global variables in global script

Game Editor comments and discussion.

Accessing global variables in global script

Postby peedalein » Fri Oct 01, 2010 2:50 pm

Hi!

I would like to store certain parameters in a single place so that it is easier for me to access/modify them. How can I do that?

What I have done so far:

Actor controls


Actor1

Key Down (right) > Script Editor

x += 10;

Key Down (left) > Script Editor

x -= 10;

Instead of "10" I would like to use a variable called "Speed". I declared a global variable "Speed".
In the Global Script Editor I put "Speed = 10;" and saved it as "VariableStor", but I do not know how to make GE access the Global Script ("x -= Speed" does not work)

As this did not work I created an actor called "Variables" with the condition Create Actor > Script Editor and put "Speed = 10;".
I am sure that there is a more elegant solution

Thanks in advance!
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

Re: Accessing global variables in global script

Postby savvy » Fri Oct 01, 2010 6:09 pm

on the player, create actor -> scrpt ed -> speed=10;
then key left -> scrpt ed -> x-=speed;
then key right -> scrpt ed -> x+=speed;

happy? this is simple var stuff :)
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Accessing global variables in global script

Postby DST » Fri Oct 01, 2010 10:46 pm

Don't set the condition in global script.

Use the variables tab to create the variable speed; if you want it to be set on game startup, use

view>createactor>

and set the variable to an amount in there.



Ge doesn't like certain things done in global script, don't ask me why.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Accessing global variables in global script

Postby Bee-Ant » Sat Oct 02, 2010 11:35 am

Peedalein, did you type this in the Global code:
Code: Select all
int Speed=10;

or
Code: Select all
#define Speed 10

Both method should work...
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Accessing global variables in global script

Postby peedalein » Mon Oct 04, 2010 10:59 am

Hello!

I did not think about the view actor being a storage for my variables. Thanks for pointing out.

Code: Select all
int Speed=10;


This did not work for me. The problem is that I already had the variable declared. Therefore I just had to define the value as in

Code: Select all
#define Speed 10



Thanks to all for helping a newbie :)
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

Re: Accessing global variables in global script

Postby lcl » Mon Oct 04, 2010 6:00 pm

peedalein wrote:Hello!

Code: Select all
int Speed=10;


This did not work for me. The problem is that I already had the variable declared.


Because the variable is already defined, you can use:
Code: Select all
Speed = 10;

:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Accessing global variables in global script

Postby Bee-Ant » Tue Oct 05, 2010 12:58 am

lcl wrote:Because the variable is already defined, you can use:
Code: Select all
Speed = 10;

:D

peedalein wrote:I declared a global variable "Speed".
In the Global Script Editor I put "Speed = 10;"

He has already did... :wink:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Accessing global variables in global script

Postby Fuzzy » Fri Nov 19, 2010 8:26 pm

If you are going to #define variables you should name them in such a way that it reminds you that they cannot be changed. Traditionally you would do this with all capitals.

#define SPEED 10
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron