Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving an instance ID #747

Closed
zatsme opened this issue Nov 14, 2018 · 15 comments
Closed

Saving an instance ID #747

zatsme opened this issue Nov 14, 2018 · 15 comments
Labels
🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution ✨ enhancement

Comments

@zatsme
Copy link
Contributor

zatsme commented Nov 14, 2018

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

@Wend1go
Copy link
Contributor

Wend1go commented Nov 15, 2018

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:

Mouse/Touch is on object MyObject              Do selected objects to variable xyz
Mouse button released

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.
Having this for Global, Scene and Object variables would also make it easier to "join" together bigger game entities consisting of multiple objects like screen filling end bosses and the like.
This could also circumvent the problem with interaction between different instances of the same object.

@zatsme zatsme changed the title Saving an object ID Saving an instance ID Nov 15, 2018
@zatsme zatsme mentioned this issue Nov 15, 2018
@4ian
Copy link
Owner

4ian commented Nov 18, 2018

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:

  1. the first to "save" the list of picked instances into a list with a name.
  2. the second to "pick" back from this saved list of instances (by giving the name of the list).

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.
Also some considerations about the scope of these lists (should there be global lists, scene lists like global and scene variables?).

@Wend1go
Copy link
Contributor

Wend1go commented Nov 19, 2018

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)

@blurymind
Copy link
Contributor

blurymind commented Nov 19, 2018 via email

@4ian
Copy link
Owner

4ian commented Nov 19, 2018

Could it also solve the following problem when adding an instance of the same object and applying it's mothers values to it?

I think in this case you'll still need to use two events:
One to copy values (MyObject.Variable(initial_height) and MyObject.Variable(initial_width)) into temporary variables.
The second one to create the object and set its scale.

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).

@zatsme
Copy link
Contributor Author

zatsme commented Nov 19, 2018

What are these in the debugger and could they be used at runtime to identify objects?

2018-11-19 2

@Lizard-13
Copy link
Contributor

Well, there's an id in the runtime object:

this.id = runtimeScene.createNewUniqueId();

But it isn't used anywhere, or very few times, because I haven't noticed it in until some months ago.

@4ian
Copy link
Owner

4ian commented Nov 19, 2018

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).
The debugger and a few other functions are the only place where they are used. In theory they could and should work without (it's just that it was convenient for the debugger).
Instead we should go toward solution that are more high level and more expressive like lists/dictionnary of objects

@zatsme
Copy link
Contributor Author

zatsme commented Nov 22, 2018

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... 🤔

@4ian
Copy link
Owner

4ian commented Dec 14, 2018

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.
So it would not be possible to create/add/remove groups during the game - even though the solution of having lists of objects can sounds similar.

@Wend1go
Copy link
Contributor

Wend1go commented Dec 14, 2018

Maybe the pixi containers could be utilized for that.

@4ian
Copy link
Owner

4ian commented Dec 14, 2018

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).
Here what we need is a way to have actions to say to "remember" a specific instance of an object, and a condition and/or action to "pick" back the instances

@zatsme
Copy link
Contributor Author

zatsme commented Dec 30, 2018

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 ?! 🤔

@Lizard-13
Copy link
Contributor

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:

proceduralchain

@zatsme
Copy link
Contributor Author

zatsme commented Dec 31, 2018

I'll give that a go later and see how it goes 🤔

@4ian 4ian added the 🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution label Feb 22, 2020
@4ian 4ian closed this as completed Feb 21, 2021
Repository owner locked and limited conversation to collaborators Feb 21, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
🙇‍♀️Careful thinking/design or refactoring needed Needs a bit of studying to come with an elegant solution ✨ enhancement
Projects
None yet
Development

No branches or pull requests

5 participants