I have tried to launch my secondary scene alone and it works fine, so i tried to launch primary and access secondary…doesn’t work. The problem seems a variable that don’t works as it should, is there any reason that i don’t know for that?
This question is too vague to be answered. You must provide a sample scene that shows the error.
for sample scene you mean something simple i guess…but the code that give the error is rather complex coz it create the dungeon and the error is on the visibility of the tiles…i can make a scene where the error doesn’t appear and the scene where it does, but is full of code anyway
Complex code does not help you to debug and manage it.
Think of splitting logic into smaller scripts, make it more modular, so it is easier to work.
Big spaghetti code - will always lead to hard debugging and inability to manage the project well.
Ahah spaghetti code give really the idea lol Who knows since i’m italian i will menage to handle the spaghetti lol I will look for a way to split it
Imagine you are dropped in a big bowl of tangled huge spaghetti which only have two ends, and rest of it is just big tangled mess. And you will be tangled in it. Most likely it will be easier to eat off own leg, rather than trying to figure out the path to one of the ends of spaghetti line
Try to think a bit more “flat” and modular, reduce number of references. Try using events more on some global object, such as this.app
. Messaging pattern helps a lot to simplify how things get referenced.
You guys are making me hungry!
lol @Vaios do as me go for lunch…just had Spaghetti alla carbonara
@max i try to think more flat but is very hard to not link together scripts the levels scene is not very complex it just use raphael script and some functions to handle it. It works fine alone, when i link it to the main scene start the problem so i cutted the code with lot of console.log to see where the problem was and is in the script to make visible the tiles…but for now can’t figure out why since no errors are displayed
here is something more simple https://playcanvas.com/editor/scene/472415 the problem is in game.js line 98 coz the value of freeCells seems get lost, to change scene you click on the church door
I strongly recommend you start learning how to use the debugger as it helps immensely with scenarios like this: http://developer.playcanvas.com/en/user-manual/scripting/debugging/
The value of freeCells is not lost, there’s an assumption that there is a value in the first place.
When you first launch the game here:
You can see in the debugger where I put a break point in the update loop of game.js and inspect the value of this.level.freeCells, it is an empty array.
So when code tries to access an element from the array, it crashes as the index is out of bounds as it’s empty.
I know the logic you are trying to do but I leave for you to solve as this is a good problem and opportunity to try some debugging with the Chrome Dev Tools and to try and walk through your own code logic.
Good luck!
I know i miss something somewhere but i don’t get why if i lunch the single scene (after change a couple of parameters of course) it works. Anyway will look for a tutorial for the debugger,i miss too many things in that
Firebug helps a lot, i see the freeCells values if i check the Level.js i have it empty if i check the Game.js
so troublesome if i use this.level.freeCells it’s empty, the same if i use this.entity.script,Level.freeCells, firebug in level.prototype show the values, i guess i miss a notion. tried also self=this but same result…sigh…depressed
EDIT: i also tried
getCells: function() {
return this.freeCells;
}
inside Levels.js
and
var freeCells=this.level.getCells();
inside Game.js
no results
Just noticed something i have this.freeCells=[]; inside the Level.js at start in declaration variables, then i have it again inside 2 functions…doesn’t that make 3 different variables 1 global and 2 locals?
Technically, as far as I can tell, your project doesn’t have ‘globals’ in the strictest sense. All the variables we are talking about here have a lifetime/scoped to the script component which in turn is tied to an entity.
So with that in mind, you have a game.js instance that is on the entity ‘Root’. In that script you have the following line:
this.level = app.root.findByName('Root').script.Level;
And as far as I can tell, this.level doesn’t change.
Now look carefully through the code logic flow when the Levels scene gets loaded and start debugging through that.
Well i know somewhere there is something wrong, so i tried to merge the 2 levels, is not big deal coz i for now i don’t need any other parts of code. Merging the 2 levels it seems to work, also if some more work is needed to load/unload entities
EDIT: also if i would have liked to make 2 scenes coz in further development i will need 2 more scenes to make it complete
Okay, I see if I can explain it further.
After the second scene is loaded, you now have one instance of Level.js on Root and another instance of Level.js on LRoot. However, your Game.js is only ever referencing Root’s Level.js so when findKeyDistanceFromPlayer in Game.js gets called from Level.js (which is triggered by the scene load), it is still referencing Root’s Level.js and not LRoot’s Level.js which is what I believe you are intended.
I found this out by putting a breakpoint in the function findKeyDistanceFromPlayer and looking at the callstack to see where it was called from. Then I worked out that you had a Level.js in the Levels scene.
What you have here is a circular dependency where Level.js and Game.js are dependent on each other but you haven’t updated the dependencies when the a new level gets loaded so Game.js is referencing the wrong Level.js script.
Edit: I believe I ‘fixed’ it in this forked project: https://playcanvas.com/project/435685/overview/debug-from-forums
so removing the level.js script from LRoot will make the trick? (I tried to remove all the js files from LRoot but didn’t work)
I believe I ‘fixed’ it in this forked project: https://playcanvas.com/project/435685/overview/debug-from-forums
You may agree/disagree with the way I fixed it but you should get the general jist of how from the project. I literally changed two lines of code.
Uhm i see, watch what happens now in my project that should be the result (way back upstairs still to be fixed)
EDIT: ehm what are the 2 lines you changed?