• 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!

[SOLVED] Using global variables as x_scale for draw_sprite_ext

K

krugen

Guest
May I ask how could I solve this problem? The global variable contains a number I would like to use as a scale. Apart from creating a variable to store the value. I know you could do string(global variable) for draw_text. How about this case?

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_data_upper_player:
draw_sprite_ext argument 5 incorrect type (string) expecting a Number (YYGF)
at gml_Object_obj_data_upper_player_Draw_0 (line 6) - draw_sprite_ext(spr_bar, 0, x + 86, y + 22, string(global.player_hp_scale), 1, 0, c_white, 1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_data_upper_player_Draw_0 (line 6)


update: Copying the global variables to the local variables do not work as well.
 

marasovec

Member
Use
Code:
global.player_hp_scale
not
Code:
string(global.player_hp_scale)
The parameter needs a number (real value) but string() converts those numbers into a string
 
Last edited:
K

krugen

Guest
I tried your suggestion before but I get:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_data_upper_player:
draw_sprite_ext argument 5 incorrect type (undefined) expecting a Number (YYGF)
at gml_Object_obj_data_upper_player_Draw_0 (line 6) - draw_sprite_ext(spr_bar, 0, x + 86, y + 22, global.player_hp_scale, 1, 0, c_white, 1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_data_upper_player_Draw_0 (line 6)
 

GMWolf

aka fel666
What did you set the variable too?
The game says it's of type undefined.
Are you perhaps reading it from a data structure like a ds_map?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Where are you declaring global.player_hp_scale and where are you assigning a value to it? What is the value, and if it's not a hard-coded one, where does it come from? What value do you expect it to have? The error message indicates that it contains an undefined value, which is usually the result of invalid data structure access.

That aside, please take a look at the manual page of the string function - this should clarify what it is used for any why it was being used in an example alongside draw_text (concatenation of strings and numbers). It's certainly not a magical function that has something to do with using variables in functions. ;)
 
K

krugen

Guest
= 1

I set it as 1 already;

Haha, I am so sorry, everyone. You are all correct. I did set the variables but I was loading the old save file which does not have the definition of this global variables.

Click new game solve the problem.

Now that I experience this, what happens if I wanted to add a new global variables when I am so far in testing the game. Click new game and play all the way back to that point? lololololol

Update: I got it! If so, just define the variable without using it. Save the game, modify the code and run again. Tada!
 
Last edited by a moderator:
D

DaMuffin

Guest
Can you show some code? I'm assuming
draw_sprite_ext argument 5 incorrect type (undefined) expecting a Number (YYGF)
means you're trying to use the variable before it's declared.

EDIT: Nvm.
 

TsukaYuriko

☄️
Forum Staff
Moderator
When you say "loading the old save file", are we talking about game_save and game_load or your own saving mechanism?

If it's your own, modify your loading code so that a default value is set for this variable regardless of whether it is stored in the save file.

If it's the default functions, these are not meant to be used across different versions of the same game and you will likely not be able to do so.
 
K

krugen

Guest
When you say "loading the old save file", are we talking about game_save and game_load or your own saving mechanism?

If it's your own, modify your loading code so that a default value is set for this variable regardless of whether it is stored in the save file.

If it's the default functions, these are not meant to be used across different versions of the same game and you will likely not be able to do so.
my own saving system
 
Top