• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Variables not applying!?

D

Drago the Shinigami

Guest
Hi,

So, recently I almost fixed my door problem, and ran into another problem: the variables set up in the instance are not working: they're going back to the object defaults.

For example, when I change dest_x and dest_y to 671 and 828 respectively, they are still act like their default values (0) when I run the game.

The object has a parent object, if that helps.
 
H

Homunculus

Guest
Is this all the information you are giving us? How are you setting those variables up? Can you provide the code or are you doing this by using the variables button in the room editor?
 
D

Drago the Shinigami

Guest
When changing it I use the variables button in the room editor.

The object in question is obj_SC_Door0, and its parent is Door_Template, which has the default values of 0.
 
A

Annoyed Grunt

Guest
When changing it I use the variables button in the room editor.

The object in question is obj_SC_Door0, and its parent is Door_Template, which has the default values of 0.
Variables set within the room editor are set before the create event fires, so it will 'reset' them.
 
D

Drago the Shinigami

Guest
I set the default variables in the Variable Definitions section of the Object creator, not the Create event...
 
H

Homunculus

Guest
Yes but do you overwrite them by any chance in the create event? As said, the create event is executed after the variables are assigned from variable definitions
 
D

Drago the Shinigami

Guest
This is all that is in the create event:
Code:
/// @description freeze
image_speed = 0;
audio_group_load(sfx0);
Nowhere in any of the code are dest_x or dest_y overwritten.
 
D

Doulos

Guest
In your original, you seem to be assuming these variables are 0 because of the behavior?
Since it seems like you are doing everything right, could you prove they are?
Would you put a write of the variables to your screen in your draw event to see what they are?
It sounds like something else might be wrong.
 
H

Homunculus

Guest
Ok then how do you check that the variables you set in the definition are in fact ignored?

You should try to output their values using a show_debug_message in create and possibly in a key press event to get some insight
 
D

Drago the Shinigami

Guest
Sorry, I should have described what happens when I run it. Instead of my character being moved to (671, 828), she is moved to (0,0).
 
D

Drago the Shinigami

Guest
I have a complex object called FADE_CAM that controls inter-room movement and fading transitions. Here is the code:

create:
Code:
/// @description set stuff.
global.a = 0.0;
global.c = c_black;
global.newX = 0;
global.newY = 0;
global.newRoom = noone;
global.GETREADYTORUMBLE = false;
show_debug_message("Stuff has been set!!")
draw GUI:
Code:
if(global.MovingRooms){
draw_set_alpha(global.a);
draw_set_color(global.c);
draw_rectangle(0,0,1023,768, false);
draw_set_alpha(1.0)
}
step:
Code:
if(global.MovingRooms)
{
    if(global.GETREADYTORUMBLE == true)
    {
        global.a = 1.0;
        global.c = c_white;
        global.GETREADYTORUMBLE = false;
    }
    if(global.a >= 1.0)
    {
        global.a = 1.0;
        increment *= -1;
        room_goto(global.newRoom);
        Magna.x = global.newX;
        Magna.y = global.newY;
    }
    global.a += increment;
    if(global.a <= 0)
    {
        increment *= -1;
        global.MovingRooms = false;
        Magna.control_lock = false;
        global.c = c_black;
    }
}
 
D

Drago the Shinigami

Guest
Also, I should mention that this is the code for collision with the player for the door:

Code:
if(!opening && !active)
{
    active = true;
    opening = true;
    audio_play_sound(sfx_door0, 100, false);
    image_speed = 1;
    global.newX = dest_x;
    global.newY = dest_y;
    global.newRoom = dest_room;
}
 
D

Doulos

Guest
I think you need to draw these two to your screen somewhere and watch it.
global.newX
global.newY

Also show_debug_message() door's variables; opening, active, dest_x, dest_y.

This seems like something you have to watch happening real time.

Edit: I am guessing
if(!opening && !active)
is coming out false.
 
D

Drago the Shinigami

Guest
Well, I just tried drawing the variables global.newX, global.newY, dest_x, and dest_y, and it turns out that after the door is created, dest_x and dest_y are put as 0.
 
D

Doulos

Guest
I just reproduced putting an object with a variable default changed and it definitely works for me.
drawing the variable value.

Could you...
Add a new variable to the door, draw that out too.
put a few random doors in your 1st convenient-est room so you seem them all right away.
set that value of each instance to something different via the room as normal.

Tell us what you see?
 
H

Homunculus

Guest
Then you are resetting those variables somewhere in the code of the door probably. The don't change by themselves, try using the search feature to see where exactly you are doing it
 
D

Drago the Shinigami

Guest
Could you...
Add a new variable to the door, draw that out too.
put a few random doors in your 1st convenient-est room so you seem them all right away.
set that value of each instance to something different via the room as normal.

Tell us what you see?
I adjusted the display so that there is a variable that determines the height of the display, and it is different for all 3 doors. However, it just displayed two 0's
 
D

Drago the Shinigami

Guest
I FIGURED IT OUT!!

It was because I didn't click the "override variable" button in the Variable Definitions for the object obj_SC_Door0!
 
Top