Jump to content


Photo

Create instance from string


  • Please log in to reply
3 replies to this topic

#1 greyzebra

greyzebra

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM:Studio

Posted 27 February 2012 - 04:55 AM

Hi All,

If I have a global string variable with value, say, "Default" I would like to be able to use it to create all default instances, say oDefaultWall, oDefaultFloor, oDefaultDoor, etc. Please explain how to do this? I understand that instance_create can only use object id.


Thanks.
  • 0

#2 iam1me

iam1me

    GMC Member

  • GMC Member
  • 380 posts
  • Version:GM8

Posted 27 February 2012 - 05:02 AM

I'm not sure why you would want to do it it like that (you should have a script where you explicitly create them), but you can use execute_string(str,arg0,arg1,...); This doesn't really save you any scripting though, as you must still construct all of the strings you pass to it. You could use an array of strings and use a for loop to iterate through them all. But its going to run slower than if you just use the instance_create() function.
  • 0

#3 greyzebra

greyzebra

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM:Studio

Posted 27 February 2012 - 05:23 AM

I tried searching execute_string in Gamemaker:HTML5 help and cannot find it. I guess it is not supported? My fault I should have informed before.


Yes my idea is to make it easier for me in generating environment in real time, so if I want an environment of a default platform with birds then I would have a global string like "Default-Birds" then the game will just create it using string operations and such. It's a canabalt type game so the game would generate it off screen and giving it negative speed as it rushes to the player onscreen. By using global string variable I can tweak it in real time and giving the player better environments rather than just randomly creating it.

I can of course use arrays which keeps a list of objects. Just wondering if there is an easier way with using string.

Edited by greyzebra, 27 February 2012 - 05:25 AM.

  • 0

#4 iam1me

iam1me

    GMC Member

  • GMC Member
  • 380 posts
  • Version:GM8

Posted 27 February 2012 - 06:02 AM

I tried searching execute_string in Gamemaker:HTML5 help and cannot find it. I guess it is not supported? My fault I should have informed before.


Yes my idea is to make it easier for me in generating environment in real time, so if I want an environment of a default platform with birds then I would have a global string like "Default-Birds" then the game will just create it using string operations and such. It's a canabalt type game so the game would generate it off screen and giving it negative speed as it rushes to the player onscreen. By using global string variable I can tweak it in real time and giving the player better environments rather than just randomly creating it.

I can of course use arrays which keeps a list of objects. Just wondering if there is an easier way with using string.


Don't use strings for it. Just use the object ids, which are global already. Then just use a switch statement in a script that will create your specified instances.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users