Functions and families... oh how I love how you interact

Discussion and feedback on Construct 2

Post » Fri Jun 05, 2015 7:30 pm

So... ya...

You make a family... you have an event that picks member from the family... you have a function call

The function acts on the family... but affects them all.

Why in the name of cheddar cheese and mud rivers does the SOL not maintain itself through a function call?

The current workaround that I know of is clunky, stupid, and a waste of events. Anyone have a solution, obvious or otherwise?

Is family overlapping
--- for each object in family -> call function (family.uid)

function call
--- pick family with UID function.param(0) -> do stuff
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 7:31 pm

SOL maintaining through functions could at least be an option? right?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 8:04 pm

I never even considered that a workaround...functions aren't meant to work on any specific objects unless specifically told to. An option to maintain the SOL could be useful, though. If anything to remove the need for "For Each Object" on functions that affect multiple of the same object.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Fri Jun 05, 2015 9:06 pm

@Tokinsom - thats a big problem if functions are not meant to act on specific objects... Kind of makes them mostly worthless, especially from a "good programing" stand point. (except for global operations, such as initiating levels and so on... but even then, why bother with functions?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 9:19 pm

Even without passing the SOL functions are still very useful. That said passing a number of objects can be done by setting a instance variable on the objects before calling the function and picking them after.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Fri Jun 05, 2015 9:25 pm

I don't really see what's so terrible about it :T For example in my game I use functions to damage enemies

+Projectile collides with enemy
-Call "Projectile_Destroy" (Projectile.UID)
-Call "Enemy_Hurt" (Enemy.UID)

+On "Projectile_Destroy"
+Pick Projectile by UID Function.Param(0)
+If Projectile.Name = "Blah"
-Do a thing with it

+On "Enemy_Hurt"
+Pick Enemy by UID Function.Param(0)
-Hurt Enemy

So now I can do many things that hurt the enemies just by calling that function, or I can hurt all enemies at once by excluding a UID. I have a higher level of control this way, and no duplicated code whatsoever.

Also sometimes you'll want to store the UID of a different instance than the one that called the function. I do this for a complex moving platform system.

*Shrug* We'll see what Ashley thinks I guess.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Fri Jun 05, 2015 10:13 pm

Construct 2 Is really not all that object oriented, and I feel that this is something that needs to be corrected. It should be like Python: Procedural and easy to get into without understanding all that OOP nonsense, but with the advanced features available when the student is ready to understand. "Pass SOL" would be a neat checkbox to have on a function call.

That said, It's not critical becuase of the workaround mentioned above. I haven't had any problem passing UIDs around. It's worked quite well for me.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Fri Jun 05, 2015 10:19 pm

I basically only use functions to break picking, or skip a tick. heh
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Fri Jun 05, 2015 10:47 pm

@Tokinsom -
@bladedpenguin -


+Projectile collides with enemy
-Call "Projectile_Destroy" (Projectile.UID)
-Call "Enemy_Hurt" (Enemy.UID)

In the case that a projectile collides with 2 enemies, only one will be hurt.

+Projectile collides with enemy
--foreach projectile
---call function...
--foreach enemy
---call function

The end result of your code is fine, assuming I understand the context, but I would say it falls under a simple use case scenario. Creating a compound object with dynamic sensors via families so that all characters in the game can inherit from it is a nightmare. If you want to role your own custom movement controllers, handling collisions and resolving collisions, implementing state control, etc... all via events... well. Things can quickly get ugly. You have layers of families, all needing functions to reduce code repetition but all objects are needing to be selected in tight ways. I jumped ship last project and switched to unity. Much easier. now this project I am getting passed the prototype stage and running up against the same problems.

In general it has been my experience that if you are using prebuilt behaviors and common use case scenarios, nothing is wrong. But the moment you need more, construct is an inflexible quagmire stuck in its own assumptions about what the game creator needs.
Last edited by ruskul on Fri Jun 05, 2015 10:48 pm, edited 1 time in total.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 10:48 pm

@newt - lol, I never thought to use them intentionally in that way. How do you skip a tick with a function?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 13 guests