How do I convert variable type?

Get help using Construct 2

Post » Sun Jul 03, 2016 4:37 am

I was curious if it is possible to change a variable type without having to change every event associated with that variable.

From Local to Global.
From Global to Local.

While we are on variables can someone tell me the difference in Static and Constant? I am aware that Constant stays the same and Static can be changed, but I am not understanding why there is a need for that. I have never used a Constant, I only use Static. If I don't make an action/event that changes a Static Variable than why would I need to make it Constant? To me it just seems like Constant and Static does the same thing.

Also in a variable is 01 the same thing as 1? I assume it ignores any 0s before any real numbers.
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

Post » Sun Jul 03, 2016 5:38 am

You just drag the variable around to change if it's local or global. Global variables are all the way to the left and local are nested under something else.

Constant, like you say can't change.
Static makes the variable like a global in that it keeps it's value and isn't reset every time like locals are.
B
91
S
31
G
103
Posts: 5,241
Reputation: 67,768

Post » Sun Jul 03, 2016 8:48 am

Thank you for the Drag and Drop, that is very helpful.

I am not understanding your explanation of Constant and Static. When are they reset? When I use a Static I never notice it changing unless an event or action made it. I've never seen a Static change by itself unless it was told to change.

What is the difference in using a Static and not changing it with Events or Actions VS using a Constant and not being able to changing it with Events or Actions? I mean if I don't need it to be changed why would I try to change it?
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

Post » Sun Jul 03, 2016 9:34 am

non Static are reset the next tick, it can change via events or actions, it will simply reset (this can be useful if some cases even though I don't use them much at all).

Static can change and will keep the new value until being changed again by an event and only then, they won't reset to their default value.

a constant is useful for organisation, instead of using the number, you use the constant in all the expression that requires it (a speed for exemple) so you just edit the value once and it becomes relevant to all actions that uses them.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Sun Jul 03, 2016 11:33 am

Depends on the 'scope' of that specific variable.

The scope of a global is 'use it everywhere in the event sheet(s)'. Roughly said: conditions & actions can see it everywhere in the event sheet.
The scope of a local is 'use it only in its own event (and subevents)'. Roughly said: conditions & actions can only see it when they are in that particulair event.

Say you have a global and two events. And you adress the global in the second event.
If you would drag this global into the first event (making it a local), you create a 'scope' problem.
Because that second event (where you adressed it as a global) can no longer see that variable anymore, as a (newly made) local it can only be adressed in that first event, no more in the second event. Conclusion: you can not do that, have to recode things, or leave it as it is.

There are more situations. But Construct is so friendly to warn you.
B
33
S
18
G
28
Posts: 2,477
Reputation: 20,918

Post » Sun Jul 03, 2016 6:33 pm

To best show what static does make an event like this:
Code: Select all
+-------------------------+
| every tick              |
+-------------------------+
   local number a=0
   local static number b=0
   +----------------------+
   | every tick           | add 1 to a
   |                      | add 1 to b
   |                      | set text to a&" "&b
   +----------------------+


notice that you'll get the text set to two numbers "1" and an increasing number. Basically static makes the local save it's value.
B
91
S
31
G
103
Posts: 5,241
Reputation: 67,768

Post » Tue Jul 05, 2016 4:36 am

I know the difference between Global, Local, Static and Constant. I was only asking what the point of a Constant was. I can only assume the reason of setting a variable as Constant would be so Construct 2 will prevent the user from changing it with events/actions. I usually just set every variable as a Static and add a description to it.
B
59
S
33
G
13
Posts: 223
Reputation: 12,105


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, SputnikCZ and 3 guests