#[SOLVED] with statement confusion

13 messages · Page 1 of 1 (latest)

gusty gorge
#

I have a variable inside an object being created via a with statement, and that variable is being set with another variable inside the object calling the with statement but gamemaker thinks both variables are coming from the created object?? I'm not entirely sure how to explain it but it's really freakin weird imo

scale = global.scale_minmax;

distance_to_judgement_line = distance_to_point(global.track1, calc_scale_y(scale, 4.65))

// Telegraph Time
telegraphed_time = 0.5;

// Calculate time to next marker
beat_duration = global.interval_duration_ms;
time_to_next_beat = (current_time / beat_duration + 1) * beat_duration - current_time;

// Adjust falling speed accordingly
time_diff = telegraphed_time - time_to_next_beat;

if time_diff > 0
{
    falling_speed = distance_to_judgement_line / time_diff;
} else
{
    falling_speed = distance_to_judgement_line / beat_duration;
}

inst_layer = layer_get_id("Instances");

// --- THE IMPORTANT LINE IS BELOW ---

with instance_create_layer(global.track1, calc_scale_y(scale, -0.5), inst_layer, obj_note)
{
    fall_speed = falling_speed;
}
hollow matrix
#

a with statement changes the scope of the code, so both fall_speed and falling_speed would be obj_note's variables here

gusty gorge
#

oh

hollow matrix
#

it's as if the code is being run on that object directly

gusty gorge
#

Ohhh right

hollow matrix
#

to get a variable from the instance that started the with, you can use other

gusty gorge
#

i havent used gamemaker for a long time so im rusty

hollow matrix
#
{
    fall_speed = other.falling_speed;
}```
gusty gorge
#

ah alright

#

i'll try that

#

yep that fixed it

#

thanks my guy

#

[SOLVED] with statement confusion