Trouble with switching layer states

About advanced scenes, and the Thyme scripting language used in Algodoo.

Trouble with switching layer states

Postby Luno » Sun Jun 05, 2016 9:26 pm

Hello,

I am making a simple game and I thought I will use hiding and showing of different layers as a simple level switching system.

I have different game objects for different levels on those layers (1,2,3) and after completing level 1, the layer 1 should be hidden and made non-interactive and layer 2 should be revealed and made interactive etc ... it more or less works when switching layers in the layer menu manually.

However when I want to do this by script, for example in onSpawn script, when I try to switch off all the layers with higher levels than 1, the behavior is quite unpredictable

following code
Code: Select all
Scene.addLayer {visible = false; id = 2; color = [1, 1, 1, 1]; dynamic = false};

will not change Layer 2 to non-dynamic and invisible (although, strangely, the reverse is possible)

- the layer "id" is correct, I tested it also through the console, e.g. when I change only the color property, it works with any layer as expected
- and, as stated above, when any layer is invisible and inactive, I can switch it on this way (setting visible and dynamic properties to true) – it seems as if addLayer does not process "false" in expected way.

Of course, it is also possible, that I make some (stupid) error. Any help or idea how to debug or circumvent this would be appreciated.
Luno
 
Posts: 5
Joined: Sat May 28, 2016 10:56 am

Re: Trouble with switching layer states

Postby grantypoo » Tue Jun 07, 2016 6:32 pm

I didnt have much luck getting help here, hope it goes better for you.

If you would share what you have of your scene so far, or else make up a sample very simple scene that just demonstrates the problem, I'd gladly download it and see if I can help.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Trouble with switching layer states

Postby Luno » Tue Jun 07, 2016 9:07 pm

Oh, well, let's try... I made a simple scene demonstrating the problem, it can be downloaded from here (I am not sure how else to post it here)

https://dl.dropboxusercontent.com/u/800 ... 20Test.phz

In the scenes 2 "buttons" live in layer 0.
There are 2 more layers (1 and 2) both hidden and not dynamic.
Clicking on one of buttons activates layer 1 or 2 due to following code being in button's onClick handler
Code: Select all
Scene.addLayer({
        visible = true;
        id = 1;
        color = [1, 1, 1, 1];
        dynamic = true
    })


This sort of "works" (though with a bug - button gets all white after executing the onClick script), however opposite behaviour does not – if I put the dynamic and visible properties to false, visible layer is not swithched off (in my minigame the layer swithcing code was in a onSpawn script - there it just did not do what it was supposed to)
Luno
 
Posts: 5
Joined: Sat May 28, 2016 10:56 am

Re: Trouble with switching layer states

Postby grantypoo » Wed Jun 08, 2016 7:15 pm

I'll try to look at it later.

To share scenes, go to the Algobox link in the upper right. You'll need to register, but then you can easily update scenes to there and share.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Trouble with switching layer states

Postby grantypoo » Thu Jun 09, 2016 2:55 am

I just looked at it real briefly, but your color changing to white is because of the line in your code...

color = [1, 1, 1, 1]

That sets the color of the object you're clicking on. So for instance changing it to color = [1, 1, 0, 1] will make your block turn yellow when you click it.

Secondly, this seems to work fine for me. What I think you're missing is explicitly turning on one layer, then turning off the next. So when you click your first box, everything works fine, layer 1 comes visible and away you go. You click the second box, and layer 2 comes visible but you also have layer 1, which you dont want. So do your code like this... which will turn off layer 1 and but make sure layer 2 and 0 stay visible and dynamic.

(e)=>{
Scene.addLayer({
visible = true;
id = 2;
color = [1, 1, 1, 1];
dynamic = true
});
Scene.addLayer({
visible = false;
id = 1;
color = [1, 1, 1, 1];
dynamic = true
});
Scene.addLayer({
visible = true;
id = 0;
color = [1, 1, 1, 1];
dynamic = true
})
}

Hope this helps... seems so simple I almost feel like I must have missed what you're asking for, but maybe you just didnt realize you could do multiple layer changes on one click?
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Trouble with switching layer states

Postby Luno » Thu Jun 09, 2016 9:26 pm

thank you for your insights, however it seems I need to make some clarifications.
although I thought my example scene will simplify the problem, it just made it bit more confusing, so forget about buttons and clicking, my trouble can be explained with few screenshots and 2 lines of code.

In my sample scene I have 3 layers (0, 1, 2)

In initial setup, I manually (in the layer menu) set Layer 1 to hidden and not dynamic - eye and gear symbols are inactive
(see red rectangle in image bellow)
Image

after I issue command through console
Code: Select all
Scene.addLayer({visible = true; id = 1; dynamic = true })


the layer becomes visible and active - eye and gear symbols are both active (white)
(see red rectangle in image bellow)
Image

So far this is expected and wanted behaviour, however if I want to hide and deactivate the same layer back to initial state and I isuue following command
Code: Select all
Scene.addLayer({visible = false; id = 1; dynamic = false })


only half of the job is done - the layer is hidden, but it is still active (the "dynamic = false part" was ignored)
see picture bellow

Image

- layer 1 is hidden, but still active, objects from other layers will still interact with the hidden objects in this layer (I tested that) - that is unwanted behaviour.

I noticed other strange behaviours, which I might be able to circumvent, but this one makes the working with layers pretty useless for my purposes ... am I missing something obvious here?
Luno
 
Posts: 5
Joined: Sat May 28, 2016 10:56 am

Re: Trouble with switching layer states

Postby grantypoo » Thu Jun 09, 2016 10:18 pm

I see now what you're saying. I just goofed around with it for 20 minutes. Yep, you can set a layer to dynamic = true and it works, but dynamic = false does not have an effect. I tried all kinds of different tricks and never could get it to work, sorry.

Not sure if this is a known bug or not.

Also I noticed that on an object, when dynamic is set to false on that layer, the objects "body" property in the script window is -1. I tried replicating that though and it just deletes the objects I change to -1, so that doesnt help.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Trouble with switching layer states

Postby Luno » Fri Jun 10, 2016 7:24 pm

so bug after all ... I am not exactly surprised, though it would be nice if it were not so.

Thanks for putting so much effort into investigating this especially that hack with setting body to -1 seemed promising :) ... that could be very useful workaround.

now I should report this bug somewhere I guess :)
Luno
 
Posts: 5
Joined: Sat May 28, 2016 10:56 am

Re: Trouble with switching layer states

Postby grantypoo » Fri Jun 10, 2016 10:55 pm

From what I can tell doing a search on the forum, layer states being dynamic or not is buggy. Looks like in the past when you changed things to dymanic and back, they lost their "glue to background" and hinges and stuff. I think probably the dev just took it out of being able to script since thats a more minor bug in his mind.

Just my $0.02.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Trouble with switching layer states

Postby Luno » Sun Jun 12, 2016 11:19 am

actually, that "losing of glue to the background" effect was next thing I was going to troubleshoot after overcoming this one, since I was getting this effect too ... well now at least I know not to go this direction :D
Luno
 
Posts: 5
Joined: Sat May 28, 2016 10:56 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests