GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Return picked instances from events-based free functions

Open D8H opened this issue 1 year ago • 4 comments

Follows:

  • https://github.com/4ian/GDevelop/pull/3163

D8H avatar Oct 22 '23 18:10 D8H

Glad to see this is back on track :D Best of luck working on this 💪

arthuro555 avatar Oct 22 '23 20:10 arthuro555

As explained, in the following comment:

  • it won't work for behaviors but it's not needed.
  • it won't work if the condition needs to iterate with for each instances, but it's an orthogonal issue (we may need to think about alternative picking lists)
  • https://github.com/4ian/GDevelop/pull/3163#issuecomment-1774176173

D8H avatar Oct 29 '23 16:10 D8H

I want to be sure to understand well this:

  • When a function (let's say, a condition) is called, we pass object lists (Hashtable<RuntimeObject[]>). In most cases, this is an "object lists" (Hashtable<RuntimeObject[]>) containing either all instances, or instances already filtered by some other conditions.
    • In rare case, we may want an empty "object lists" (this is the case when your function is creating a new object. You want the object as parameter, but with an empty list).
  • This "object lists" (Hashtable<RuntimeObject[]>) is passed to the function. Most of the time, the function just uses it for conditions, creating new arrays that are filtered.
  • When the function finishes, we get out of the function and continue with the next condition (if the condition was true). So far, no filtering could have happened, because we did not change the "objects list" (Hashtable<RuntimeObject[]>).

Here with this change:

  • We allow to filter the list passed as argument to the function. This means we filter eventsFunctionContext.getObjectsLists("name of the object passed to the function")... this is actually already written in the doc You can alter the list and this will alter the objects picked for the next conditions/actions/events..
  • So it seems all good.
  • Question though: what if I use an empty object lists as the parameter of my function? I will receive empty lists, which is fine. Let's say I then create an object in the function. Will this add: 1) add the object to the objects list automatically, I can just finish my function and it works or 2) do I need to use this new action?

My thinking is that 1) is the answer, because when you use "Create", you've not run any condition on the object before (it would not make sense. Well you can but these conditions will be false), so the "Create" will directly add the object to the object lists passed as parameter... is this correct? Can we add a test case for it?

4ian avatar Nov 07 '23 10:11 4ian

As discussed, let's add a test if two objects created in a function (using an object passed as parameter) and pick only the second thanks to this action, and see if it's properly "returned" to the caller.

4ian avatar Nov 13 '23 11:11 4ian