Saving an instance ID #2321
Replies: 15 comments
-
Well you could basically achieve this via linked objects extension but never the less I like your idea. Maybe as a new type of variable in addition to Number and String so that we could write something like:
The ToString function could then convert the object into its ID. But it could get problematic if there is more than just one Object in the filter. |
Beta Was this translation helpful? Give feedback.
-
It's an interesting problem 😊First thing to note, I'm not sure that saving "IDs" is really the way to go because it's not necessarily something that I want to keep in the game engine (to have ID attributed to objects). In fact most of the game engine don't use IDs at all and I'm almost sure I could remove the usage of it in the two/three places where it's used :) This being said, you are right that it would be interesting to somehow "store" one (or more) specific instance(s) to easily and efficiently retrieve it later. It's something that you can do with variables but performance could be better because GD will still need to scan through all the instances. In another way, what we could need is a "hashmap" or at least a list of instances. I don't have an immediate solution for now, but I think there is a simple and powerful concept to find here! EDIT: for example, we could introduce an extension/feature with two action/condition:
Should be quite easy to use. Implementation can still be a bit tricky because you have to ensure that any deleted object is removed from the lists. |
Beta Was this translation helpful? Give feedback.
-
Sounds interesting.
(This currently doesn't work and adds the size it to both instances) |
Beta Was this translation helpful? Give feedback.
-
Could help with saving and loading instance states/variables
…On Mon, 19 Nov 2018 07:19 Wend1go ***@***.*** wrote:
Sounds interesting.
Could it also solve the following problem when adding an instance of the
same object and applying it's mothers values to it?
Trigger Once Add object MyObject at position MyObject.X(), MyObject.Y()
Do MyObject.Variable(initial_height) to the Hight's scale of MyObject
Do MyObject.Variable(initial_width) to the Width's scale of MyObject
(This currently doesn't work and adds the size it to both instances)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#747 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGMbVeirT11SoLtb6uU18sqHEAEaAoSJks5uwluRgaJpZM4YetfK>
.
|
Beta Was this translation helpful? Give feedback.
-
I think in this case you'll still need to use two events: This is because the solution I'm proposing is a way to store/save list of objects, but this don't change the way object lists are used in events (i.e: for each object, there is a unique list of objects picked for it). |
Beta Was this translation helpful? Give feedback.
-
What are these in the debugger and could they be used at runtime to identify objects? |
Beta Was this translation helpful? Give feedback.
-
Well, there's an id in the runtime object: GDevelop/GDJS/Runtime/runtimeobject.js Line 34 in 32f56f3 But it isn't used anywhere, or very few times, because I haven't noticed it in until some months ago. |
Beta Was this translation helpful? Give feedback.
-
Yes, these are IDs but as I said it's not necessarily something that I want to keep in the game engine. You can't use them in events (and that's a good thing because they will be gone at some point :) They would not be faster than using a variable anyway). |
Beta Was this translation helpful? Give feedback.
-
Lists would be good, although would they not act just like groups do already? Why not make groups accessible to the runtime, create group and add to group actions might be all that is needed, we can already ierate through a group and the order doesn't seem to change. Deleting an instance removes it from the group already... 🤔 |
Beta Was this translation helpful? Give feedback.
-
Answering late, but groups do not exist at runtime. They are only a logical way of grouping objects in events. When events are transformed to code, groups are used to create the events/actions/conditions for the associated objects, but are then totally invisible in the game. |
Beta Was this translation helpful? Give feedback.
-
Maybe the pixi containers could be utilized for that. |
Beta Was this translation helpful? Give feedback.
-
Pixi containers are more a way to group pixi objects that are rendered on screen (for example, each layers are containers, containing the pixi objects of each instance that is on the layer). The game engine is also agnostic toward pixi: it could run without (and is actually running without pixi when you're exporting with Cocos2d-JS - even if I don't particularly recommend it). |
Beta Was this translation helpful? Give feedback.
-
Some more to add here, when creating a physical rope in the new Physics2 you have to create each joint in an individual action so for a long rope you have tons of actions. In code you'd have a loop and create each object on the fly and joint it to the preceding object, it's a pain how we have to do it now. So will we be able to do this via some list system in future or will we have to resort to Javascript to achieve this? Also, slightly related is the question of parenting, it came up on Discord and it's something that adds value to GDevelop! So like in Godot, Unity etc You can define a parent object and add children so when the parent moves the children follow, maybe it links in with lists somewhere ?! 🤔 |
Beta Was this translation helpful? Give feedback.
-
Not tested but something like this should create procedural chains, you use an index counter, if the index is pair create an object A, otherwise create a B. Then after creating any of them check which one is the latest in the chain (index = last index) and which one is the previous one (index = last index -1) and joint them: |
Beta Was this translation helpful? Give feedback.
-
I'll give that a go later and see how it goes 🤔 |
Beta Was this translation helpful? Give feedback.
-
It would be useful to save an instance ID after it has been picked so we can use it outside of the current pick condition.
i.e. The current example I'm working on highlights the nearest instance while I press the mouse button and I want to be able to un-highlight it later in the code once I release the button.
I'm sure there would be other uses for this 🤔
Zat
Beta Was this translation helpful? Give feedback.
All reactions