Direct type-field assignment fails, intermediate variable works
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:
During the first loop, only
is correctly assigned the value of
. The remaining array elements stay at
.During the second loop, when using an intermediate variable (
), all elements from
to
are assigned correctly.This suggests that the issue occurs specifically when assigning directly from a field of a user-defined type.
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]
Code:
var2[0].x
Code:
pac.x
Code:
0
Code:
temp
Code:
var2[0]
Code:
var2[9]
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.
4 days 12 hours ago #124
by Franck
Replied by Franck on topic Direct type-field assignment fails, intermediate variable works
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.
4 days 6 hours ago #125
by ludojoey
Replied by ludojoey on topic Direct type-field assignment fails, intermediate variable works
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!
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.
2 days 7 hours ago - 2 days 7 hours ago #131
by ludojoey
Replied by ludojoey on topic Direct type-field assignment fails, intermediate variable works
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.
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