How do I temporary change variables and revert it back

Get help using Construct 2

Post » Mon Mar 28, 2016 6:02 am

Good day, C2 community!
Say, I have a RPG Hero with stats: Atk, Def, and so on. And a Hero have an item that can be activated and deactivated at any time by pressing the button.
I need to do the following: when an item is Active, the Hero have temporal stats changes: +2Atk/+1Def and so on, and when item is Inactive, the Hero have its initial stats.
I've tried to use "while" loop:
Code: Select all
While [item is Active] Atk = initial Atk + bonus

and System-Compare Values event:
Code: Select all
itemIsActive = 1
   Atk = initial Atk + bonus

but I get the same result: in every tick Atk increases at "bonus" value. I understand why it happens, but this is not what I need :(
So, please help me. Thank you.
B
4
S
1
Posts: 5
Reputation: 312

Post » Mon Mar 28, 2016 9:00 am

your second approach is fine. Just add a condition system > trigger once while true

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Mon Mar 28, 2016 10:34 am

fm4fanAT, thank you very much! It works fine now. As I understand, I have to do the same thing to remove temporary effect:
Code: Select all
itemIsActive = 0
Trigger once
   Atk = initial Atk - bonus

Correct?
B
4
S
1
Posts: 5
Reputation: 312

Post » Mon Mar 28, 2016 6:37 pm

correct
but in this case

itemIsActive = 0
Trigger once
Atk = initial Atk

You can also use only 2 variables and get rid of the "initial Atk". Then you would do Atk = Atk - bonus to get back to normal

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707


Return to How do I....?

Who is online

Users browsing this forum: David181, OBLIVION, tarek2 and 17 guests