GameMaker: Studio

GameMaker: Studio

Zobrazit statistiky:
Assigning sprites using strings?
I know you can change sprites by setting sprite_index to the index of the sprite you want, but is there any way to point at said index via a string (something like: sprite_index = "player_up")? The closest thing I could find online was execute_string, and that's apparently a function that was taken out when Studio was released.
< >
Zobrazeno 19 z 9 komentářů
There's no need to use a string as all sprites, objects, rooms, scripts, backgrounds and so on have their own storage variable of their own name.

If you have a sprite "player_up" then setting sprite_index = player_up will work.
BBX původně napsal:
There's no need to use a string as all sprites, objects, rooms, scripts, backgrounds and so on have their own storage variable of their own name.

If you have a sprite "player_up" then setting sprite_index = player_up will work.

That's true, but what if I have many sprites with "_up" and "_down" variants and am trying to change them dynamically? In the RPG I'm making, I'm trying to make it so that the NPCs can turn towards me when I'm talking to them, however, I want to use just one NPC object who has a variable determining its type, that way when it's talked to from the right, for example, the code to turn them would be something like 'sprite_index = type + "_" + direction', except to my knowledge there's nothing in GameMaker allowing for this kind of code to happen (except for execute_string which, as I've already mentioned, has been removed)
I don't think you can do that, I know you can in QBasic. You can try a combination of val(string(type)) which might work, but I'm sure it adds a space.

Another possible option (untested) is to make an ennumerator on start up that contains your facings, then you han have type.direction (as opposed to _) - might not work.
it appears sprite_get_string() can fetch a sprite's resource name as string, and conversely asset_get_index() can use such a string to look up the sprite (though the latter's link is 404'ing for me on the online doc atm. The former[docs.yoyogames.com] should give a proper direction, tho).
Naposledy upravil Sera; 14. led. 2015 v 14.20
Ya, I have a backup of the documentation. They give an example of
var obj = asset_get_index("obj_Enemy_" + string(global.Level)); if obj > -1 { instance_create(random(room_width), random(room_height), obj); }

In this case instead of string(global.Level) you'd be using "direction".
Zaron X původně napsal:
it appears sprite_get_string() can fetch a sprite's resource name as string, and conversely asset_get_index() can use such a string to look up the sprite (though the latter's link is 404'ing for me on the online doc atm. The former[docs.yoyogames.com] should give a proper direction, tho).

BBX původně napsal:
Ya, I have a backup of the documentation. They give an example of
var obj = asset_get_index("obj_Enemy_" + string(global.Level)); if obj > -1 { instance_create(random(room_width), random(room_height), obj); }

In this case instead of string(global.Level) you'd be using "direction".

asset_get_index() did the job perfectly, thank you very much for your help!
BBX původně napsal:

asset_get_index("obj_Enemy_" + string(global.Level));

I know it's an old post but I really want to thank you, I was really stuck on that one! I love internet. And thanks ❄Goodyob❄ for asking the question in the first place.:steamhappy:
VegaBiggs původně napsal:
BBX původně napsal:

asset_get_index("obj_Enemy_" + string(global.Level));

I know it's an old post but I really want to thank you, I was really stuck on that one! I love internet. And thanks ❄Goodyob❄ for asking the question in the first place.:steamhappy:


ik this is now a really old post but funny enough this was the only correct method that fixed my problem so thank yall!!
JopGamerNL původně napsal:
VegaBiggs původně napsal:

I know it's an old post but I really want to thank you, I was really stuck on that one! I love internet. And thanks ❄Goodyob❄ for asking the question in the first place.:steamhappy:


ik this is now a really old post but funny enough this was the only correct method that fixed my problem so thank yall!!
Ik this is now even older post but even funnily enough this thread was the solution to my problem. Thanks for the OP.
< >
Zobrazeno 19 z 9 komentářů
Na stránku: 1530 50