YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
26 stars 8 forks source link

In-Game: variable_global_set()'s value is not type "Any" #7328

Open metangrobo opened 3 months ago

metangrobo commented 3 months ago

Description

When making a game, i wanted to add a global variable based on keyboard_check. However, it is a boolean, so i searched how to add booleans and in the manual it had variable_global_set(name,val) and the "val"(aka the value of the variable) was showed to be Any type, so it's compatible to any value, including boolean. however, when i tried it, it crashed and the error report said it "expected a number value".

Manual Link

https://manual.gamemaker.io/beta/en/index.htm#t=GameMaker_Language%2FGML_Reference%2FVariable_Functions%2Fvariable_global_set.htm

tabularelf commented 3 months ago

The docs are correct here. Something in your code is wrong.

Can you show the exact code you used? Because it's working fine on my end. variable_global_set("TestInput", keyboard_check(vk_up)); You also don't need variable_global_set for this. You can just use global. directly. global.TestInput = keyboard_check(vk_up);

If you have done keyboard_check("A"), then that would be wrong. keyboard_check documentation requires a number. And that's where the error would be, not setting a global variable. There is a work around using ord on letters to convert them into their numerical value. See https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Game_Input/Keyboard_Input/keyboard_check.htm

YYDan commented 3 months ago

As already wonderfully described above, this doesn't sound like a bug - and you say you're getting a code error dialog telling you the issue, so that's not a "crash". This does sound like a coding issue (and we do not offer coding support), but in order to know for sure we would need a small sample to be uploaded here so we could see the results you're getting.