Image scale works only at second call.

Get help using Construct 2

Post » Wed Oct 29, 2014 6:16 pm

Hello everybody!
I am trying to load background image (Sprite) from file, then scale its size and set position.
Image
On first call of "create_hex", image is loaded, but it isnt scaled of moved to correct position.
On second call, image remain same (already loaded), but it finally scaled and moved.
Why it works only at second call?
Thank you and sorry for my bad English.
B
3
Posts: 4
Reputation: 185

Post » Wed Oct 29, 2014 7:23 pm

My guess would be that it has something to do with this:
Wait 0 Seconds
Wait 0 seconds is designed to postpone until the end of the current run of events (not even the next tick - the same tick, but after all other events).

Explanation :

Condition 1
.. Event1
.. Event2

In this case , event 1 & event 2 will occur in the same tick

Condition 1
.. Event1
.. Wait 0 seconds
.. Event2

Putting a 0 seconds will insure that Event2 will only occur after Event1 is finished

Some examples ...

On start of layout
.. Destroy Object1
.. Set Variable1 to Object1.Count

Here , the two events occur in the same tick , meaning the object is created in the same moment as the variable is changed , The object isn't destroyed yet , so the variable is assigned before the object count is egal to zero ... Doesn't work .

If you place "Wait 0 seconds" between the two , C2 will destroy the instance , wait until it is successfully destroyed , and then assign the variable , in this case , set it to 0 ...

This trick is very useful when you need to call a function then call another depending on the result of the last one ...

From this tutorial (https://www.scirra.com/tutorials/510/ad ... ct2-offers) and Ashley's explaination of wait (https://www.scirra.com/tutorials/56/how ... ait-action)

Try using a wait 0 after loading so it finishes load before moving on.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 635
Reputation: 9,331

Post » Wed Oct 29, 2014 9:36 pm

Thanks for reply! :)
i will read those tutorial. What kind of sorcery is wait? I change that code to:
Image
notice those two local variables
and it works! but it create another problem :( result:
Image
(left - correct)
(right - actual with wait function.)
When i added wait function, it ignores assing of TILE_COUNT_X and TILE_COUNT_Y and leaves its default value.
B
3
Posts: 4
Reputation: 185

Post » Wed Oct 29, 2014 9:53 pm

Now, i have this code:
Image
its print (7) which is bad value and generate map... and in the end it print correct value (4). I dont really get it :(
B
3
Posts: 4
Reputation: 185

Post » Wed Oct 29, 2014 11:29 pm

From what I understand the wait 0 simple makes Construct2 finish the action above this tick and return next pass so you would not want to use it after something that is necessary for the rest of the function each tick...

Usually its is needed when you destroy something and then recreate or count its instances all in the same event because all events happen simultaneously Construct2 will destroy or count the instance at the same time it is doing the other stuff and that causes quirks.. I would say put the wait 0 right after your destroy family and leave the rest the same and see if it helps.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 635
Reputation: 9,331

Post » Thu Oct 30, 2014 7:55 am

Still dont work :(
My problem is, that wait() function changing local variable to its default value.
Image
and result:
0 4
1 7
where 4 is new value and 7 is default value. Why is those value different?
B
3
Posts: 4
Reputation: 185


Return to How do I....?

Who is online

Users browsing this forum: Clark Thy Lord and 1 guest