GML Coordinates not storing values correctly (or wholly)

Dawn

Member
I wrote a script for alarm events that an object changes coordinates over time to the destination.

I set the length, the direction and the duration (steps) and the alarm will move the object's coordinates by [length/duration] for [duration] steps. The code below is not an actual code and excludes the repeating part.

Code:
//STEP
var len=total_length/n;
var len_x=lengthdir_x(len,dir);
var len_y=lengthdir_y(len,dir);
x+=len_x;
y+=len_y
//run this n times
The sum of (length/duration)*duration and the length should match... and they don't.
So, I set additional variables for storing coordinates then copied the values to coordinates then it fixed the problem.

Code:
//STEP
var len=total_length/n;
var len_x=lengthdir_x(len,dir);
var len_y=lengthdir_y(len,dir);
ACTUAL_X+=len_x;
ACTUAL_Y+=len_y;
x=ACTUAL_X;
y=ACTUAL_Y;
//run this n times
I got a feeling that this is actually intended for maybe the optimization issue, but I'm not sure. Honestly I think this is pretty dumb.
 

Dawn

Member
Total length is just set from other script. There's nothing unusual about that.
I found out something weird about coordinates and normal variables.

This is the alarm script that you don't really need to read.
Code:
if slide_goal>0 && slide_time<slide_goal {
    slide_time++;
 
    var len;
    switch slide_cur{
    case 0:
        len=slide_len/slide_goal;
    break;
    case 1:
        len=slide_len*(sin(.5*pi*((slide_time)/slide_goal))
            -sin(.5*pi*((slide_time-1)/slide_goal)));
    break;
    case 2:
        len=slide_len*(sin(.5*pi*(-1+(slide_time)/slide_goal))
            -sin(.5*pi*(-1+(slide_time-1)/slide_goal)));
    break;
    }
 
    var len_x=lengthdir_x(len,slide_dir);
    var len_y=lengthdir_y(len,slide_dir);
 
    X_TEMP+=len_x;
    Y_TEMP+=len_y;
    x=X_TEMP;
    y=Y_TEMP;

    draw_x=x;
    draw_y=y;
}

if slide_time<slide_goal {
    alarm[slide_alarm]=1;
}
else {
    slide_len=0;
    slide_dir=0;
    slide_cur=0;
 
    slide_goal=-1;
    slide_time=-1;
}
Let's say the object's x is moving from 250 to 190 over 45 steps. (1.3333... per step)

This is the "x" values from directly adding value to the coordinates.
1/45,248.6666717529
2/45,247.3333435059
3/45,246.0000152588
4/45,244.6666870117
5/45,243.3333587646
6/45,242.0000305176
7/45,240.6667022705
8/45,239.3333740234
9/45,238.0000457764
10/45,236.6667175293
11/45,235.3333892822
12/45,234.0000610352
13/45,232.6667327881
14/45,231.3334045410
15/45,230.0000762939
16/45,228.6667480469
17/45,227.3334197998
18/45,226.0000915527
19/45,224.6667633057
20/45,223.3334350586
21/45,222.0001068115
22/45,220.6667785645
23/45,219.3334503174
24/45,218.0001220703
25/45,216.6667938232
26/45,215.3334655762
27/45,214.0001373291
28/45,212.6668090820
29/45,211.3334808350
30/45,210.0001525879
31/45,208.6668243408
32/45,207.3334960938
33/45,206.0001678467
34/45,204.6668395996
35/45,203.3335113525
36/45,202.0001831055
37/45,200.6668548584
38/45,199.3335266113
39/45,198.0001983643
40/45,196.6668701172
41/45,195.3335418701
42/45,194.0002136230
43/45,192.6668853760
44/45,191.3335571289
45/45,190.0002288818
Of course this is not right.

Then here's the value of "x" from X_TEMP (x=X_TEMP).
1/45,248.6666717529
2/45,247.3333282471
3/45,246.0000000000
4/45,244.6666717529
5/45,243.3333282471
6/45,242.0000000000
7/45,240.6666717529
8/45,239.3333282471
9/45,238.0000000000
10/45,236.6666717529
11/45,235.3333282471
12/45,234.0000000000
13/45,232.6666717529
14/45,231.3333282471
15/45,230.0000000000
16/45,228.6666717529
17/45,227.3333282471
18/45,226.0000000000
19/45,224.6666717529
20/45,223.3333282471
21/45,222.0000000000
22/45,220.6666717529
23/45,219.3333282471
24/45,218.0000000000
25/45,216.6666717529
26/45,215.3333282471
27/45,214.0000000000
28/45,212.6666717529
29/45,211.3333282471
30/45,210.0000000000
31/45,208.6666717529
32/45,207.3333282471
33/45,206.0000000000
34/45,204.6666717529
35/45,203.3333282471
36/45,202.0000000000
37/45,200.6666717529
38/45,199.3333282471
39/45,198.0000000000
40/45,196.6666717529
41/45,195.3333282471
42/45,194.0000000000
43/45,192.6666717529
44/45,191.3333282471
45/45,190.0000000000
This worked perfectly.

Now then, the weird part.
1/45,
248.6666717529
248.6666666269

2/45,
247.3333282471
247.3333332539

3/45,
246.0000000000
245.9999998808

4/45,
244.6666717529
244.6666665077

5/45,
243.3333282471
243.3333331347

6/45,
242.0000000000
241.9999997616

7/45,
240.6666717529
240.6666663885

8/45,
239.3333282471
239.3333330154

9/45,
238.0000000000
237.9999996424

10/45,
236.6666717529
236.6666662693

11/45,
235.3333282471
235.3333328962

12/45,
234.0000000000
233.9999995232

13/45,
232.6666717529
232.6666661501

14/45,
231.3333282471
231.3333327770

15/45,
230.0000000000
229.9999994040

16/45,
228.6666717529
228.6666660309

17/45,
227.3333282471
227.3333326578

18/45,
226.0000000000
225.9999992847

19/45,
224.6666717529
224.6666659117

20/45,
223.3333282471
223.3333325386

21/45,
222.0000000000
221.9999991655

22/45,
220.6666717529
220.6666657925

23/45,
219.3333282471
219.3333324194

24/45,
218.0000000000
217.9999990463

25/45,
216.6666717529
216.6666656733

26/45,
215.3333282471
215.3333323002

27/45,
214.0000000000
213.9999989271

28/45,
212.6666717529
212.6666655540

29/45,
211.3333282471
211.3333321810

30/45,
210.0000000000
209.9999988079

31/45,
208.6666717529
208.6666654348

32/45,
207.3333282471
207.3333320618

33/45,
206.0000000000
205.9999986887

34/45,
204.6666717529
204.6666653156

35/45,
203.3333282471
203.3333319426

36/45,
202.0000000000
201.9999985695

37/45,
200.6666717529
200.6666651964

38/45,
199.3333282471
199.3333318233

39/45,
198.0000000000
197.9999984503

40/45,
196.6666717529
196.6666650772

41/45,
195.3333282471
195.3333317041

42/45,
194.0000000000
193.9999983311

43/45,
192.6666717529
192.6666649580

44/45,
191.3333282471
191.3333315849

45/45,
190.0000000000
189.9999982119
The upper values are "x" that copied X_TEMP (x=X_TEMP) and the lower values are "X_TEMP", the original. This is kinda confusing.
 
Last edited:
Top