Scirra / Construct-feature-requests

A place to submit feature requests and suggestions for Construct.
https://www.construct.net
11 stars 1 forks source link

Custom Actions - Return Type (variable) #355

Open SalmanShhh opened 2 months ago

SalmanShhh commented 2 months ago

Reviewed guidelines

Checked for duplicate suggestions

Summary

Custom Actions have been great for organising functions under objects especially in projects where theres heavy use of them for complex behaviours and even simpler ones in addition to make it easier to share code between projects.

if there was something missing it would be great to have the ability to return variables via custom actions similar to how they work in Functions but with the added benefits that come from picking with Custom Actions + organisational benefits of the actions being inside the objects when searching.

Possible workarounds or alternatives

currently its creating normal functions, but having to make variants of those functions with several layers of picking involved to pick the specific or correct instances to return the target type/data and dealing with issues in casting the correct type of variable.

Proposed solution

for example I use Custom Actions to sort out a save system that looks a lot like this.

image with the need to get certain data back I needed to use a function purely dedicated to getting specific data. luckily in the example this can be totally fine but if it was dealing with several objects for different types of behaviours it would get very intensive very quickly.

Why is this idea important?

would love this to be considered, since it would open up more opportunities to do complex things that would help with improving workflow of projects and even making optimisation tricks such as Time-Slicing more feasible to do in Construct for large projects that would be able to make use of it.

Additional remarks

in a personal note it would greatly help with the development on the next title from Hibernian Workshop that I'm working on.

ruskul commented 1 month ago

I thought there was already a feature request for custom expressions, but I can't seem to find it now. +1

I will add that you an alternative that I use to pass data is an array. Whenever a custom action is called that has a return value, the caller passes a parameter "index" that indicates where in an array I should put the return value. If the custom action also calls other custom actions with return values, those actions are passed (index +1). This allows an arbitrary number of nested actions with minimal overhead and boiler plate.

Using it in action looks roughly like this:

CallAction(index , otherparameters) SetSomeVar = ReturnArray.GetAt(index)

What I don't like is that it IS more work, and using it in conditions requires multiple events with sub events. and makes the events less legible.