Alternative to Get Object By Name

0 favourites
  • 10 posts
From the Asset Store
Template for an alternative to falling shapes, fully documented in comments and video
  • I ran into the need for a getObjectByName() a couple of days ago trying to store spawn point names with doors. I was able to work around it by approximating a point and then using "Pick nearest to" to get the UID. Breakable if I change my layout in any meaningful way, but workable.

    But now I'm in a spot where that won't work. I'm storing state data for my game in Dictionaries. 1 for each state/level (dialog lines, object positions, etc) with a naming convention. Since the dictionaries aren't physically in the layout, I can't think of anyway to detect them. Even if I could, I know the exact name of what I want and it seems like I should be able to just get that Dictionary by name.

    something like: getObjectByName("Level_010").spawnX

    I'm figuring that if there isn't a getObjectByName() function out there, that there must be an easy alternative to do this simple procedure. When I scraped the forums/manual/tutorials, all I could find was "no, you have to use the UID or IID". I'm not seeing how to do that in this particular case.

    How do I?! <img src="smileys/smiley4.gif" border="0" align="middle" />

  • Wouldn't Dictionary(levelNumber).Get("Stuff") work? That is the IID way. Assuming you have one dictionary representing each level, if you have multiple you could have separate dictionary objects for each dictionary that you need for one level.

  • Thanks for the reply, vee41!

    What is levelNumber in your example? It seems like that would still have to be a label of some sort. That's what I'm getting stuck on. If it's the IID, I have no idea what that is since it's created at run time.

  • Due to the way minification works, you can't expect to call a name like that.

    What you have to do is use picking, to get the object into the selected objects list.

    You can use uid, as well as iid, however those are prone to change at runtime. I would suggest the simplest method... using a variable.

    Like: If global variable makeObject = 1, system make sprite at x,y.

    Its a little long and draw out, but its hard to screw up.

  • Thanks, newt. I get what you're saying about minification and the need to cut out the name... I'm not sure I understand your variable example though. Here's exactly what I'm trying to do for more clarity:

    <img src="http://www.gabemiller.com/images/chart.jpg" border="0" />

    I know the Family, I need to get the Dictionary Object so I can set the dialog to the instance variable value. I have been trying to store the Dictionary name to the global variable, which isn't working...obviously. I'd store its UID if I knew what it was...

    How are you suggesting I use a variable to solve this? Am I missing a key ingredient? Thanks again for your help!

  • Give the family an instance variable "name" and set it to "level1", "level2", "level3" etc for each dictionary. Then you can pick the dictionary whose name value = "level" & currentLevel.

  • Thanks, Ramones! That makes sense. Although it seems like accessing the name would be basically the same thing (grumble).

    For some reason, I can't seem to find the expression to make that work though. I see how to check the key on the family, but not "some generic object". After reading the Families section, this seems like it should work... but it doesn't.

    <img src="http://www.gabemiller.com/images/c2function.jpg" border="0" />

    Sorry this thread won't die. I think it's just down to syntax at this point though.

  • levelName should be a family instance variable and not a dictionary key. And then the condition would be "levels -> compare instance variable".

    <img src="https://dl.dropbox.com/u/8367729/construct/pics/dictionaryFamily.PNG" border="0" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • OK, got it working. I'm indebted to you on two problems now, Ramones! I have to say that the community on these forums is super helpful and fast to react! They should have a badge for "props for helping" that users could give to their benefactors. <img src="smileys/smiley1.gif" border="0" align="middle" />

    I got it working this time because I had an instance variable called "playerChatter" and just used Levels.playerChatter instead of Levels.Get("playerChatter").

    The thing I was missing was that I mistook instance variables for keys in the case of a dictionary for some reason. Dictionaries seemed like a good solution to store static data like an in-engine version of a JSON file. Now that I'm looking at it, it seems that you can only set keys using in-game actions, so I can't set them up offline. And they must be in memory the whole time? Is that right? If that's the case, maybe I'd be better off using JSON or XML and loading them as I need them. Instance variables are easier, but it's a lame way to store dialog, and a waste of memory.

  • Yeah you can't add keys to dictionaries in the editor, you'd be better off using project files and JSON/XML like you said.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)