Why is this not working!?

Mikael.K

Member
In my obj_system object i have this code

CREATE EVENT:
GML:
global.debug = 0;
KEY PRESS - O EVENT:
GML:
global.debug = !global.debug;
I just want to toggle my debug text on/off with the O key. Doesn't work.

However if i move the Key Press - O event and it's code and put it in any other object it works fine. What could be the cause?
 

Mikael.K

Member
Same with this code. It doesn't work in the obj_system object, but works if i put it in the obj_player object.
How come some code works in one object, and not in another?

GML:
/// @description Change input device
switch(global.input) {
    case "KEYBOARD":
        global.input = "GAMEPAD";
    break;
    case "GAMEPAD":
        global.input = "KEYBOARD";
    break;
}
 

Mikael.K

Member
@EvanSki
0 is a boolean im sure? Like i wrote, the same code works fine in any other object. The code changes global.debug from 0 to 1.

@FrostyCat
Ofcourse, the obj_system is in the room. And all other code the object is running is working fine.

Must be something with the obj_system object that makes it not run some code... hmm
 

TheouAegis

Member
Put inside your Player Object's Step Event

show_debug_message(instance_number(obj_system))

The console Window should get flooded with 1.
 

Nidoking

Member
How MANY obj_system are in the room?

I bet it's two, and that the code you posted here is running. Twice. Think about what that does to the values you're affecting.
 

woods

Member
maybe not two instances of obj_system..
but two bits of the same code... OP said it works in the player object.... i would poke around for leftovers and forgotten bits of code that were shuffled around.
(first hand experience on that part ;o))
 

Nidoking

Member
maybe not two instances of obj_system..
but two bits of the same code... OP said it works in the player object....
Two player objects is much easier to notice than two invisible system objects. And it's really easy to set persistence and still put the system object in each room.
 

woods

Member
However if i move the Key Press - O event and it's code and put it in any other object it works fine.
this is the line that caught my attention.. shuffling code around to different instances, during your troubleshooting .. you can accidentally leave one behind.
 

Nidoking

Member
And if one is left behind, then it would affect the same operation no matter where it's placed. Either of the above will appear to have no effect if it's run an even number of times in one step, and will appear to function correctly if it runs an odd number of times. I'm just going with Occam's Razor here. The simplest explanation is that there's a persistent system object and also a system object in each room.
 

Roderick

Member
@EvanSki
0 is a boolean im sure? Like i wrote, the same code works fine in any other object. The code changes global.debug from 0 to 1.
0 is not a bool; booleans are true or false, nothing else.

GML will interpret non-bools as true or false depending on their value, but this is not true in all languages. It is best practice to properly define it as false when you declare it.

That said, you are correct. This is not the source of your bug.

I recommend adding a show_debug_message immediately after you change the variable. If you see the message more than once per keypress, then you have multiple copies of the object. If you only see one message, there's a different issue that will require further debugging.
 
Top