variables

Get help using Construct 2

Post » Sat Apr 27, 2013 8:26 pm

How to set 4 variables to one variable?
i mean when i have four this same sprites and each sprite have variable with 25 hp
4x 25 hp give me 100 hp so this 100 should be displayed in one visible on screen variable, right?

For exapmple when first and third sprite have 20 hp Global hp variable display 90 hp
B
98
S
22
G
36
Posts: 1,850
Reputation: 29,408

Post » Sat Apr 27, 2013 8:34 pm

If I understand well, you could set an instance Variable hp, set by default to 25 for each one, and a global variable, GlobalHp, then, you set global HP to Sprite(0).hp + Sprite(1).hp + Sprite(2).hp + Sprite(3).hp, it should work, I didn't test it though
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
43
S
18
G
17
Posts: 2,099
Reputation: 15,907

Post » Sat Apr 27, 2013 9:28 pm

You can use 'For each' and add the instance variable to a total variable and display that.
ImageImageImage
B
70
S
19
G
142
Posts: 3,328
Reputation: 83,738

Post » Sat Apr 27, 2013 9:40 pm

@Aphrodite almost right but i have this same sprite x4 no 'sprite1' 'sprite2' just one sprite copied four times

@blackhornet Can you explain more ?
B
98
S
22
G
36
Posts: 1,850
Reputation: 29,408

Post » Sat Apr 27, 2013 9:43 pm

[QUOTE=delgado] @Aphrodite almost right but i have this same sprite x4 no 'sprite1' 'sprite2' just one sprite copied four times
[/QUOTE]
Sprite(0) is the first instance 0 based of Sprite, the () are used to select a particular instance, as you can verify, "(" and ")" can't be used as a Object name, because of this

Sprite(0) is the object Sprite, but only the instance 0
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
43
S
18
G
17
Posts: 2,099
Reputation: 15,907

Post » Sat Apr 27, 2013 9:46 pm

ImageImageImage
B
70
S
19
G
142
Posts: 3,328
Reputation: 83,738

Post » Sun Apr 28, 2013 12:23 am

@blackhornet this is what i need but How did you set wariables to " "




Anyway i edit yours capx and when i substract from sprites, text dont show substracted number

https://dl.dropboxusercontent.com/u/44710358/test.capxdelgado2013-04-28 00:24:23
B
98
S
22
G
36
Posts: 1,850
Reputation: 29,408

Post » Sun Apr 28, 2013 12:48 am

[QUOTE=delgado] @blackhornet this is what i need but How did you set wariables to " "



Anyway i edit yours capx and when i substract from sprites, text dont show substracted number

https://dl.dropboxusercontent.com/u/44710358/test.capx[/QUOTE]

That is a little problem: The text is showing the value of total

but total isn't re-calculated when a budynek is clicked, replace the "on start of layout" by an "every tick", and it will be fine (because it will be reset to 0, recalculated, and finally the display changes, before, there were no recalculating)

EDIT: you can also only recalculate when the fish is clicked, but in this case, you must assure than the value at start of layout will be good tooAphrodite2013-04-28 00:49:48
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
43
S
18
G
17
Posts: 2,099
Reputation: 15,907

Post » Sun Apr 28, 2013 3:03 am

ImageImageImage
B
70
S
19
G
142
Posts: 3,328
Reputation: 83,738

Post » Sun Apr 28, 2013 1:51 pm

@blackhornet lot of work and this is it Thanks!
B
98
S
22
G
36
Posts: 1,850
Reputation: 29,408

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot], zenox98 and 12 guests