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

Placeholder message

I

ItsRealGaming

Guest
hOi, I have a problem about the placeholder message. For example, I got 3 weapons with 3 descriptions.

When I start the game, the weapon and the description is drawn like normal. If I add 4th weapon and I don't add the description, how can I make it drawn the message like: "Missing variable: <global.weaponDescription[ /*The current weapon*/ ]>"?. For example: "Missing variable: <global.weaponDescription[OrbitBall]>"

I can provide you my variable and code:
Code:
draw_text(75,180,"Weapon Description:##" + string(global.weaponDescription[global.currentWeapon]));
 
I

ItsRealGaming

Guest
How can I check if an array existed? hm... variable_local_exists?
 
Last edited by a moderator:

Joe Ellis

Member
There's no way to check if a local variable exists, probably cus there's no need, as long as you check the script to see if it was created or not,
with an array, you can do: "if is_array(variable)"

But the thing is, with your question, like why would you make a weapon with no description? and the way you've got it so that it displays the description, it's just (and only) gonna cause an error of there is no\none

You could if you want it to have no description, add a description for it which is just an empty string, simply: description[@ index] = ""
 

TheouAegis

Member
A switch is pretty bad to use compared to an array, but you could throw a switch inside a script which returns the description string and have the default case be
Code:
case default: return "Missing variable: <global.weaponDescription["+global.currentWeapon+"]>";
Or if global.currentWeapon doesn't contain a string, use object_get_name(global.currentWeapon) there instead.

I understand the desire to implement something like this, but as far as I can think, devs usually just had a data structure of descriptions (in your case) and would assign indexes of those descriptions. If the index wasn't assigned, the debugging message would appear instead. So global.weaponDescription[] would be an array of values from 0 for <unassigned> (your error message) up to however many descriptions were actually created. So the description itself would be referenced like global.weaponDescriptionString[global.Description[global.currentWeapon]].
 
I

ItsRealGaming

Guest
I see, well, this is pretty suck. GameMaker's possibility would be infinity (or +100) if this is a function. Thank for your help anyway :). The reason I do this is when I add a new weapon, I will look around if I miss something (the description for example). :/
 

Yal

šŸ§ *penguin noises*
GMC Elder
Or you could make a script that adds all the info for the weapon at once, so you physically can't forget something? :p
upload_2019-6-15_15-50-49.png
 
I

ItsRealGaming

Guest
WOO... That was something... This is really nice and easy to work with... Thank you for doing this... This is easier than I expected :)
 
Top