Problem with variables and force of gravity (a crash)

For questions about using Classic.

Post » Wed Oct 01, 2008 5:32 pm

First of all, I have a variable called g and 2 istances of the same sprite.
When a player collides with an instance, it is deleted and if g=0 then g=1 and if g=1 then g=0.
But construct reads events top-down, so g stays at 0.

I tried using the tricks (1-Global('g')) but that didn't work because I found a crash :

make 2 events like this :

When g = 0 set force of gravity to 20
When g = 1 set force of gravity to -20

Try to run the layout, it crashes Construct...

Is there any work-around this bug? I need it badly for my game.
B
2
S
2
G
5
Posts: 512
Reputation: 2,674

Post » Wed Oct 01, 2008 6:07 pm

Can you upload the .cap that crashes to the tracker? That way we can fix the crash instead of trying to avoid it...
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Wed Oct 01, 2008 7:25 pm

The crash might be a bug that needs fixing, but your (1-Global('g') is wrong.

[code:1c9dxf6b]
+Player collides with sprite
-Set g to (0 minus g)
-Set force of gravity to g
[/code:1c9dxf6b]

This will toggle back and forth between 20 and -20.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Oct 01, 2008 7:33 pm

[quote="deadeye":2douikgz]The crash might be a bug that needs fixing, but your (1-Global('g') is wrong.

[code:2douikgz]
+Player collides with sprite
-Set g to (0 minus g)
-Set force of gravity to g
[/code:2douikgz]

This will toggle back and forth between 20 and -20.[/quote:2douikgz]

sorry, won't this toggle between 0 and -1? Also I can't post the cap right now, because im not at the main pc
B
2
S
2
G
5
Posts: 512
Reputation: 2,674

Post » Wed Oct 01, 2008 7:41 pm

[quote="SuperV":18qz3s5f]sorry, won't this toggle between 0 and -1?[/quote:18qz3s5f]

Nope. And sorry, I forgot to say "make the initial value for g either 20 or -20."

So if g is 20 then 0-g (zero minus twenty) will be -20.
And if g is -20 then 0-g (zero minus minus twenty) will be 20.

Just try it. It will work :wink:
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest