Create Global Variable Action

Get help using Construct 2

Post » Fri Aug 02, 2013 12:50 am

Is there any way I can make my game to create a global variable when an something is done and can ve deleted when the action is end?
B
5
Posts: 6
Reputation: 541

Post » Fri Aug 02, 2013 2:25 am

Why?
B
12
S
5
G
2
Posts: 59
Reputation: 3,859

Post » Fri Aug 02, 2013 2:27 am

[QUOTE=David Flook] Why?[/QUOTE]
Because I need for my game? DarKeX2013-08-02 02:32:41
B
5
Posts: 6
Reputation: 541

Post » Fri Aug 02, 2013 3:10 am

it is not possible via normal means. Global variables must be declared at the topmost part of a layout.

there are ways to simulate them though.
it is difficult to explain ways when we do not know exactly how you will be using them though.
B
5
S
1
Posts: 26
Reputation: 427

Post » Fri Aug 02, 2013 3:35 am

Variables are NOT objects, you only can change their values.
B
97
S
35
G
29
Posts: 3,139
Reputation: 28,371

Post » Fri Aug 02, 2013 3:56 am

if you want something that stores data to be deleted and created at runtime, you could try a dictionnary, you can create and delete "keys", which can be used to store a value under a name
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat Aug 03, 2013 12:59 am

I need somthing like a database.
B
5
Posts: 6
Reputation: 541

Post » Sat Aug 03, 2013 3:29 am

You could use an array to hold your global variables.
So if you will have 10 maximum ever needed at one time, create an array with x=10, y=1, z=1. Since you are asking for globals, I assume you will be using another layout to access them, so maybe have these layouts load the variable(s) it uses and test if valid, then take action. One way to make valid is if you only use positive values then set the variable = -1 when 'deleted'.

Another way would be to use any object that has 'instance variables' and set the object to global. Use the instance variables you create as described above.
B
5
S
1
Posts: 26
Reputation: 427

Post » Sat Aug 03, 2013 9:43 am

@DarKeX

Look into the Dictionary object. It is basically what you're refering to, a dynamic database : )
B
10
S
3
Posts: 233
Reputation: 1,537


Return to How do I....?

Who is online

Users browsing this forum: dop2000, FacuLNF, Lordshiva1948, Matei511 and 61 guests