Direct type-field assignment fails, intermediate variable works

More
5 days 3 hours ago - 5 days 3 hours ago #123 by ludojoey
There seems to be a bug when assigning a variable from another variable when the source variable belongs to a user-defined type containing two fields.(There may be other cases as well, but I haven't tested all possible combinations.)Example:
Code:
type player { int x; int y; }; type othertype { int x; int y; }; player pac; othertype var2[10]; pac.x = 1234; pac.y = 9999; for(byte i; i < 10; i++) { var2[i].x = pac.x; print("var2[", i, "].x=", var2[i].x, "\n"); } int temp; for(byte i; i < 10; i++) { temp = pac.x; var2[i].x = temp; print("var2[", i, "].x=", var2[i].x, "\n"); }[/i][/i][/i][/i]
During the first loop, only
Code:
var2[0].x
is correctly assigned the value of
Code:
pac.x
. The remaining array elements stay at
Code:
0
.During the second loop, when using an intermediate variable (
Code:
temp
), all elements from
Code:
var2[0]
to
Code:
var2[9]
are assigned correctly.This suggests that the issue occurs specifically when assigning directly from a field of a user-defined type.
Last edit: 5 days 3 hours ago by ludojoey.
The following user(s) said Thank You: Franck

Please Log in or Create an account to join the conversation.

More
4 days 12 hours ago #124 by Franck
Strange. I've got the field for each index correctly assigned in the first loop. Did you test on 0.7.7 ?

Please Log in or Create an account to join the conversation.

More
4 days 6 hours ago #125 by ludojoey
Yes, 0.7.7

I ran again my test today : you are right, everything is indexed correctly.

Anyway, yesterday, it was not.
I worked a lot on the computer : may be I did something that caused the problem.

I will investigate, and if I find what produced this behaviour, I will let you know!
The following user(s) said Thank You: Franck

Please Log in or Create an account to join the conversation.

More
2 days 7 hours ago - 2 days 7 hours ago #131 by ludojoey
Well, I wasn't able to reproduce the bug with the small test script.
However, here is a piece of code of my game NNGAME that trigger the issue (when Fire button is pressed).

At line 255; you will find :

//bullets.X=pac.X;
//bullets.Y=pac.Y;

int a;
a=pac.X;
bullets.X=a;
a=pac.Y;
bullets.Y=a;


The commented-out code should behave exactly the same as the code using the intermediate variable "a"

However, it doesn't.

Try recompiling the game after replacing the current code with the commented-out version. You'll see that it doesn't behave as expected.

This makes me suspect that the issue may be related to direct assignment from a structure member, while using an intermediate variable works correctly.
Last edit: 2 days 7 hours ago by ludojoey.
The following user(s) said Thank You: Franck

Please Log in or Create an account to join the conversation.

Time to create page: 0.165 seconds
Powered by Kunena Forum