[size=200:2vewwiq0]Download Construct 2 public preview 36
[size=85:2vewwiq0]Link to release 35
As promised, this build brings global and local
However, first of all, there's been an improvement to collisions: now rotated objects overlap when their rotated
bounding boxes overlap, as opposed to using unrotated bounding boxes which are always much too big for rotated objects. This makes collisions much more useful now, even though there aren't fine collisions just yet.
Back to variables: the main change is both global and local variables appear, and are added and edited, in the event sheet itself!
Variables at the 'root scope' (at the top of an event sheet, or anywhere they aren't a subevent) become global variables. These work exactly like global variables in Classic: they keep their value between layouts, and you can use them from any
event sheet, not just the one you created it in.
Variables which are subevents to another event become 'local variables'. You can see in the picture above they have a different icon too. These work slightly differently. They reset their value every tick back to their original value. Also, they can only be used in their 'scope'. This means any 'sibling' subevents. For example, in the above picture, 'MyLocal' can be accessed by any subevents of 'every tick', but not
anywhere else. They're intended to be a temporary holding space for calculations, like you might have used a 'temp' global or instance variable for in Classic. Their scope is similar to how scope works in programming languages. This has the advantage that you can reuse names where scope does not overlap. You could have a 'sum' local variable in one subevent, and another 'sum' local variable somewhere else in that event sheet, used for another purpose.
As an added bonus the expressions panel lists all variables available in the current scope under the System object:
Local variables turned out to be a very complex feature to write - there may be bugs in this version. Let me know if you find any.
There are three more things to watch out for:
- You can drag local variables around like ordinary events. However, this changes their scope. This can mean events already using the variable can no longer access it. In this case, those events disappear, and a balloon tip appears at the mouse notifying you this happened. You can just undo this or drag it back and they'll reappear, though.
- Copying and pasting or dragging around events referencing local variables is tricky, because you can't paste them anywhere outside the scope of the local variables they reference. If you try to do this a message appears and you are prevented from doing it. This could be annoying for day to day use though. Let me know how you find it. Perhaps it could be worked around with a "do you want to add missing local variables?" type prompt.
- You can't yet put an expression in the initial value of either a global or local variable - this should be added in a future build.
Anyways, hope you enjoy, let me know if you have any thoughts or more ideas!
- [Feature] Global & local variables (see above)
- [Change] Previously collisions only tested axis-aligned bounding boxes. This doesn't work well for rotated objects, which often register collisions when close but not touching. Now collisions are tested with object-aligned bounding boxes (i.e. the box rotates with the object). This is much better for collisions between rotated objects until fine collisions come in future.