GMS 2 How can I combine a string and integer, then use it as an object ID?

(I'm only a few days into using GML, but I have other programming experience)

Alright, basically I have a very simple button/door system. What I do is, I make a door's ID "door1", and corresponding button with "button1", which is fine. But apparently I can't use the same ID's between different rooms.

My solution was to call them something like "<room number>door1" and "<room number>button1", since most levels would have few doors/buttons I won't bother with the door/button numbers part for now.

All I want to do is, combine an integer and string and use that as an object ID, so how could I do this? Also I'm not really looking for solutions for the door/button thing, just the variable mumbo jumbo. Thank you :)
 

TheouAegis

Member
string+integer is

asset_get_index(stringy_variable + string(real_variable));

You should typically avoid using it, though. It's one carryover from GM8 that I wish YoYo abandoned, but as long as object_get_name() and similar functions exist, it's a given. It's very useful, but to me it's just bloat. *shrug* I prefer my resource names to be constants, not strings embedded in the PROM.
 

Joe Ellis

Member
Hmm, I would make a global array, and put each door's id into it (in each door's creation code)

For door 1:
set global.doors[@ 1] to that door's id

and set the button that should open it do that index in the button's creation code:

door_index = 1

Then when the button is pressed you can use the button's index to make the certain door open with the same index:

with global.doors[door_index]
{scr_open_door()}
 
Hmm, I would make a global array, and put each door's id into it (in each door's creation code)

For door 1:
set global.doors[@ 1] to that door's id

and set the button that should open it do that index in the button's creation code:

door_index = 1

Then when the button is pressed you can use the button's index to make the certain door open with the same index:

with global.doors[door_index]
{scr_open_door()}
this is what I ended up doing after posting, it's much more practical. but thanks!
 
Top