SOLVED Test if sprite exists problems

V

VansiusProductions

Guest
Hi guys,
For my game i am implementing a system where the user can download texture packs to change how the game looks. Here's some code from the parent object:
Code:
nameTemp = object_get_name(object_index)
nameTemp2 = string_replace(nameTemp, "obj_", "")
sprfile = working_directory + "\packs\test\" + nameTemp2 + ".png"
if !(is_undefined(sprfile)) {
    if !(sprite_exists(1)) index = 1
    if !(sprite_exists(2)) index = 2
    spr = sprite_add(sprfile,index,false,false,0,0)
    sprite_index = spr
}
Now each children object will get its name that corresponds to the file names (the objects are named like obj_ball, so nameTemp2 will be ball). Then in sprfile it searches for the file in the directory, if such file exists, it will add it to the game and change its sprite index,
However for some objects, when sprfile doesn't find the file, it still changes its sprite index so it becomes empty. How do i prevent this?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Then in sprfile it searches for the file in the directory, if such file exists
You are not checking whether any files exist anywhere in your code.


Where did you learn that your way of using is_undefined is valid? The reason why I'm asking is because it's not, and I'm having difficulties comprehending why you'd assume it to be correct.
Please read the corresponding manual entry to learn what the function is really used for: https://docs.yoyogames.com/source/d...e/001_gml language overview/is_undefined.html

The same goes for sprite_exists, which you seem to be using completely out of context. You seem to be assuming that it allows you to check whether a specified subimage exists in a graphics file...? If so... I once again have no idea what made you think that.
Manual entry: https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_exists.html

Your usage of the subimg argument of sprite_exists is also not correct. Please re-read the manual entry carefully: https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_add.html


Learning what these functions are used for (and therefore what they are not meant to be used for, and thus can't be used for) should help you understand what I meant with my first statement.
 
V

VansiusProductions

Guest
You are not checking whether any files exist anywhere in your code.


Where did you learn that your way of using is_undefined is valid? The reason why I'm asking is because it's not, and I'm having difficulties comprehending why you'd assume it to be correct.
Please read the corresponding manual entry to learn what the function is really used for: https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/is_undefined.html

The same goes for sprite_exists, which you seem to be using completely out of context. You seem to be assuming that it allows you to check whether a specified subimage exists in a graphics file...? If so... I once again have no idea what made you think that.
Manual entry: https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_exists.html

Your usage of the subimg argument of sprite_exists is also not correct. Please re-read the manual entry carefully: https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_add.html


Learning what these functions are used for (and therefore what they are not meant to be used for, and thus can't be used for) should help you understand what I meant with my first statement.
sorry i forgot to edit the thread title as solved before you answered because i already figured it out :p
 
Top