Picking Objects does not work inside functions

Bugs will be moved here once resolved.

Post » Mon Oct 09, 2017 8:36 pm

Problem Description
You can`t compare instance variables of objects that has been set inside functions with the oficial Function plugin. Let`s say you create a function called SET that sets an instance variable value of a sprite to 1 (And logs it`s value)
Then you create a function called GET that only logs the value of the instance variable. If you run SET and then GET after (Inside an On Start of Layout event) the SET will set the value and correctly log the value. The GET function that runs after will fail to log the value (Will log the old value stored in that variable)
That being said... you can`t pick objects based on their instance variables unless you wait for the next frame. Waiting for the next frame is a terrible workaround. I`m uploading a capx with 3 tests. Only the test without any functions works as expected.

Attach a Capx
https://www.dropbox.com/s/9n1cruqrutv1g ... .capx?dl=0

Description of Capx
The capx has 3 tests where a "Card" object and a "CardImage" object are created on start of layout. CardImage stores inside itself the UID of the Card created. After that, the scale of both Card and CardImage are changed to 0.1. Test1 has two functions (SpawnCard and SetScale), Test2 has one function (SetScale) and the card is spawned "hard-coded" inside an On Start of Layout event. The Test3 is made without any function (So it does not support parameters without ugly go horse workarounds) but it works by successfully picking the right CardImage and resizing it. I`m not using containers for this because what I need is more complex and containers are too limited to this (Because they can only allow one instance of each object per Container Group)

Steps to Reproduce Bug
  • Run the tests inside the capx

Observed Result
What happens?
When using functions, events do not recognize the value of instance variables and fail to pick objects to change their scale. The SetScale functions just works correctly one frame after the objects Card and CardImage were created
Expected Result
What do you expect to happen?
To work just like the Test3 without functions
Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (NOT TESTED)

Operating System and Service Pack
Windows 10

Construct 2 Version ID
Construct 2 r244 64bits
B
7
S
2
Posts: 31
Reputation: 947

Post » Mon Oct 09, 2017 8:58 pm

Nevermind you're doing something weird.

Objects don't really exist till the end of their event.
Last edited by newt on Mon Oct 09, 2017 9:18 pm, edited 1 time in total.
Image ImageImage
B
169
S
50
G
174
Posts: 8,325
Reputation: 110,794

Post » Mon Oct 09, 2017 9:10 pm

It's not a bug, you're just trying to do everything in one tick.
B
46
S
16
G
78
Posts: 2,168
Reputation: 46,353

Post » Tue Oct 10, 2017 6:45 pm

You can do everything in the same tick without functions and can't with functions. Objects DO exist at the time they are created.
B
7
S
2
Posts: 31
Reputation: 947

Post » Tue Oct 10, 2017 6:55 pm

newt wrote:Nevermind you're doing something weird.

Objects don't really exist till the end of their event.


I disagree (Run my Test3). Without functions you can freely modify a created object right after "Create Object" and everything will work just fine.
If you have the SAME events inside a function it has the strange behavior of changing instance variables just inside the function context for that tick.

Functions are useless if you have to wait 1 tick to access values modified by them.

The problem extends not only for objects created in the same tick. If you have a simple function that changes an instance variable value of an existing object, log the new value inside the function and then log the value AFTER running the function you will see that the value is logged correctly ONLY inside the function. The log AFTER the function was called will log the old value until the next frame.

This is either a bug or a terrible design
B
7
S
2
Posts: 31
Reputation: 947

Post » Tue Oct 10, 2017 6:57 pm

Actually they don't exist - fully. You can not pick, except by UID, until the next top level event after an object is created. There are countless threads on this - it is just part of the design.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue Oct 10, 2017 7:05 pm

blackhornet wrote:Actually they don't exist - fully. You can not pick, except by UID, until the next top level event after an object is created. There are countless threads on this - it is just part of the design.


With functions not even if you run the function in a separated "top level event" it will not work, you will have to wait until next frame. Without functions it works. Again... either a bug or a bad design
B
7
S
2
Posts: 31
Reputation: 947

Post » Tue Oct 10, 2017 7:11 pm

It will, but you have to pass in both UIDs and pick by UID.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue Oct 10, 2017 7:51 pm

When you create an object that object is picked for that event, and you can do anything you like to that object within that event, so long as the scope is within that tier, or sub tier of that tier. If you create a subevent on the same tier then it is no longer picked. Also, new instances will be picked, and old ones are taken out of the sol.

If you wish to use functions then you must do something like call a system wait as it takes a tick to register for conditional picking.

I don't consider the way it is as bad design. Its linear, and easy to follow. You create something, and then you talk about...
On the other hand, calling functions to modify instances is like nightmare fuel.

Imo, functions should only be called to reuse code, or to break picking.
You're doing one of those things.
Image ImageImage
B
169
S
50
G
174
Posts: 8,325
Reputation: 110,794

Post » Tue Oct 10, 2017 8:46 pm

ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Next

Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest