anyone discover any bugs using On Function calls with create

Discussion and feedback on Construct 2

Post » Tue Sep 08, 2015 12:58 am

my question is are On Function calls running the normal built in javascript for each loops like written in the blog for performance fixes? i was told every time you have stuff like this

>>On function initCreate
>>Repeat 1 times
>>Object1 Boolone is true
>>Object1 BoolTwo is false
create this and do stuff with it

it would run automatic for each loops from built in javascript object scoping.. it doesnt seem to be doing it. or atleast not with create events I had to add a For Each Object1 to the times it repeats for it to work
B
4
Posts: 27
Reputation: 254

Post » Tue Sep 08, 2015 1:01 am

Objects are being created on the next tick, if I'm correct. So you got to use On created instead.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Sep 08, 2015 1:21 am

Functions are only run when you call them, and when they are they are run as if they were inserted in place of the call minus any picking.

Creating objects does create the object right there and picks it, but you can't pick it as normal elsewhere until the next toplevel event. Here's some info on that to help explain what occurs:
is-this-a-bug-can-t-pick-objects-created-in-the-same-ti_p890954?#p890954
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Sep 08, 2015 2:31 am

strange it did as you said because I can make it a command but not loop through it at the start without for each
B
4
Posts: 27
Reputation: 254

Post » Tue Sep 08, 2015 7:51 am

JavaScript doesn't have a built-in init() function, that is, it's not a part of the language. But it's not uncommon (in a lot of languages) for individual programmers to create their own init() function for initialisation stuff.

A particular init() function may be used to initialise the whole webpage, in which case it would probably be called from document.ready or onload processing, or it may be to initialise a particular type of object, or...well, you name it.

What any given init() does specifically is really up to whatever the person who wrote it needed it to do. Some types of code don't need any initialisation.
B
3
Posts: 27
Reputation: 217

Post » Tue Sep 08, 2015 9:13 am

Ok, I'm lost now.
All this talk about JavaScript is irrelevant since events aren't JavaScript.

Re-reading the op is the question why only one object is created with those events?
The system actions are only done once so you would have to add a for each to create an object for each of another one that meets that condition. Now if you used a sprite action instead it would automatically be done for all the picked instances of that sprite.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Sep 08, 2015 5:35 pm

apparently they are

Unnecessary 'For-each' loops

The System For-each looping condition is useful in lots of circumstances, but it is often used where it makes no difference. Going back to How Events Work, conditions are tested for each instance, and then actions are run for each instance that met the event's conditions. As that sentence suggests, the Construct 2 engine already has built-in for-each loops to help events run as you expect. For example, consider the following event:
An ordinary event in Construct 2


Construct 2 already runs the event like this: for each monster that is hunting, set the angle towards the player's position. However we often see events that look like this:
An example of a redundant for each loop

In this case the use of the system For each loop is redundant. It shows a misunderstanding of how Construct 2 events already work. It does not change the meaning of the event at all - the engine was already doing that. Again, there are two disadvantages to this kind of event: mainly that it is confusing to include events that have no effect, but also performance is a bigger concern in this case. The engine's own for-each loop happens directly at the javascript level, and is fast; for-each loops happening at the event level involve the overhead of the event engine, which while we've worked hard to optimise, should be avoided if unnecessary.


https[br]://www.scirra[br].com[br]/blog/141/common-mis-used-events-and-gotchas

maybe im wrong but this is what Ashley wrote I assumed it meant the events run using javascript or something.
B
4
Posts: 27
Reputation: 254


Return to Construct 2 General

Who is online

Users browsing this forum: kiki4construct and 4 guests