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

Discussion and feedback on Construct 2

Post » Fri Jun 05, 2015 10:53 pm

An approach more consistent with C2's design would be:

1. A way to grab the current SOL for an object/family/entire gamestate as a value (say, a JSON string).

2. A complimentary "Restore SOL" condition that this value could be passed to.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Fri Jun 05, 2015 11:04 pm

Well, you can skip a tick anywhere with wait. A function works well when you need to get past a gpu update, or created objects which are automatically picked.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Fri Jun 05, 2015 11:05 pm

@TiAm

That would be perfect.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 11:06 pm

@newt - so you just have a function that has wait in it? - getting passed created objects is a good use case.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri Jun 05, 2015 11:18 pm

Im not 100%, but I think functions are only synchronous to the cpu, so a draw call can be after.

Edit:
Also you can break the created picking of newly created objects by creating a new sub event, as long as the object wasn't created in the parent.
Then a variable can be used in all the same ways a function can, so technically you don't really need functions anyway.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Sat Jun 06, 2015 12:18 am

@newt - Events run, scene is rendered. Repeat. A function will always occur before the scene is drawn if it is called during the events. And... I'm still confused, what do you mean a variable can be used in the same ways as a function? You mean you set a variable to something and then if it is something you do do something, rather than calling a function?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Sat Jun 06, 2015 2:45 am

Yep.
As a trigger.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Sat Jun 06, 2015 7:19 pm

@newt interesting. Though, that would n't work like a function in the sense that the function runs right away, but the triggering variable would have to wait till it was polled. And that could involve alot of polling in a big project.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Mon Jun 08, 2015 5:37 pm

ruskul wrote: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.

Yeah... there are a number of simple use cases that C2 makes you work pretty hard for :(

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 assumption about what the game creator needs.

I have spent as much time searching for plugins and behaviors and writing javascript as I have actually using C2. I think that C2, flexible as it is, has taught me that real gamedevs actually do need to write code, or else loosen up and let the game be "not quite right". I've chosen the former.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Jun 09, 2015 12:15 pm

Carrying over the SOL would have quite a high performance cost. Since the function can go on to modify the SOL, but then has to be able to restore the state when the function returns, the SOL lists must be copied before the function is called. If you have picked say 1000 instances with some event before calling a function, then every time the function is called with "carry SOL" it must duplicate an array with 1000 items. Used naively (on-by-default, or if there is a checkbox and you just get in to the habit of always checking it) you could end up with a very high CPU cost for this feature.

Passing a UID and picking it in the function is a good technique: the "pick by UID" condition works in constant time (it just directly picks the instance without having to check every instance like normal conditions) so this is an efficient pattern. If you need multiple instances, just putting the picking conditions back in the function is probably not much less efficient than any kind of "carry SOL" feature, and could actually be more efficient since you can make sure you don't carry the SOL for any unrelated objects the function doesn't actually need.

Functions are generally supposed to be some kind of independent, re-usable bit of work, and I'm not entirely convinced how sensible it is to design them to use the SOL of the caller, since that seems to mix together the responsibilities of the calling event and the function. There's not really a way it "should" work, since programming languages don't use SOLs so there's no good analogy looking at traditional programming languages. This type of question is, as far as I'm aware, totally unique to C2.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: tumira and 4 guests