![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | C:\Flavius |
This is my code:
func draw_epicicles (nbOfSegments, listPositionOfSegments, nbOfEpicicles):
var Position1 = Vector2();
var Position2 = Vector2();
var color = Color(0.0, 1.0, 1.0);
var Times = nbOfEpicicles + 1;
var n = 0;
var m = 0;
for i in range (nbOfSegments):
Position1 = listPositionOfSegments[i];
n = floor(i*Times/nbOfSegments);
m = i*Times/nbOfSegments;
if (m>=0.9):
i = i * Times - nbOfSegments * n;
Position2 = listPositionOfSegments[i*Times];
draw_line(Position1, Position2, color, 3, false);
pass
As example values to test this programs I have set nbOfEpicicles to 2, which means Times is equal to 3 (2+1). nbOfSegments is equal to 50 in this test. And that’s it for the variables
So it should draw a line for every value of i.
I run this program. It gets an error which says 57 is not a valid value for the array listPositionOFSegments. That is because it’s size is equal to 50, to the number of segments.
I use the mouse to see the value of every variable.
i = 19 when I get this error. That’s why it’s trying to use 57 as the index, because it is 19 * 3.
But, I have set a few lines of code that should prevent this by comparing i * Times/nbOfSegments with 1. So it compares 19 * 3/50 which is equal to 1,14 with 1.
1.14 is clearly greater than 1.
This means it should subtract 50 to 57 so it should now be 7. It doesn’t
The reason is because for some reason i*Times/50 is set to 1 instead of 1.14 which is clearly wrong. I need it to be a float number so that the program knows it has to subtract 50 * 1 to 57 to set it to 7.
Also for some reason I made the program compare m with 0.9 instead of 1, so it is obviously greater than 0.9 but even tho I done that, it still doesn’t subtract 50 to 57.
I also realised I can’t change the value of i all the time to be less than 50 because it would make this an infinite recursion but that is easily solved.
So any way of solving this?
Thank you in advance!