I am trying to load background image (Sprite) from file, then scale its size and set position.
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.
My guess would be that it has something to do with this:
[quote:7h5i7h5t]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).
In this case , event 1 & event 2 will occur in the same tick
.. Wait 0 seconds
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.
Develop games in your browser. Powerful, performant & highly capable.
Thanks for reply!
i will read those tutorial. What kind of sorcery is wait? I change that code to:
notice those two local variables
and it works! but it create another problem result:
(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.
Now, i have this code:
its print (7) which is bad value and generate map... and in the end it print correct value (4). I dont really get it
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.
Still dont work
My problem is, that wait() function changing local variable to its default value.
where 4 is new value and 7 is default value. Why is those value different?