How do I swap local values?

Get help using Construct 2

Post » Sat Jul 19, 2014 11:35 am

Hi guys! My problem is that I don't understand how to swap values in instance variables.

Let's imagine I have sprite stuff_1 and sprite stuff_2 with family instance value 1 and 2.

I want to set stuff_1 with stuff_2 value and stuff_2 with stuff_1 value.

Because of Construct works from up to down, I have the situation that one of the values is already changed and give the other the changed value. I mean that in our situation stuff_1 has value 2 and gives it back to stuff_2, and value stuff_2 was not changed. Who knows how to simply fix it?
Last edited by Bass_X on Sat Jul 19, 2014 12:20 pm, edited 1 time in total.
B
7
S
1
Posts: 73
Reputation: 603

Post » Sat Jul 19, 2014 11:53 am

Do you actually mean local variables or instance variables?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Jul 19, 2014 12:18 pm

@codah
Family instance variables in my case,sorry for mistake
B
7
S
1
Posts: 73
Reputation: 603

Post » Sat Jul 19, 2014 12:26 pm

How about using a detour and adding an instance variable swapvalue..
first set swapvalue and only after the swap is completed set the values swapped to that value..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Jul 19, 2014 12:54 pm

Bass_X wrote:@codah
Family instance variables in my case,sorry for mistake


The general case for swapping values is

temp=A
A=B
B=temp
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Aug 14, 2014 4:15 am

This was really useful, thank you. Trying to use it for an inventory management system, it's tough but I'm almost there!
B
9
S
2
Posts: 56
Reputation: 668


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, KTML5, XavierOrionGames and 5 guests