Reload using external file

Hi guys,

Been a while since I posted here!

I hope you guys can help with an issue I’m having…

I’m trying to “reload” a level using some variables that have been “preset” earlier from another file.

However when I try to reload it, I get the following error:

[lua]Runtime error
/Users/----/-----/-----/director.lua:440: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’
/Users/----/-----/-----/director.lua:440: in function
(tail call): ?
?: in function <?:930>
?: in function <?:214>[/lua]
It reloads everything apart from 3 variables - 2 of which are from the external file - I don’t see why it shouldn’t reload them as the level works perfectly the first time it is played. [import]uid: 40538 topic_id: 12819 reply_id: 312819[/import]

We really can’t tell anything at all from the above except that you are trying to insert something that likely doesn’t exist.

If you’re using director are you cancelling your Runtime listener when you change scenes? [import]uid: 52491 topic_id: 12819 reply_id: 47063[/import]

I managed to narrow it down to a collision listener being attached to one of the “external” variables when the player dies.

But if I don’t (insert) it in localGroup, it seems to work although you cannot see the player, just the physical outline in hybrid mode. The other 2 variables also show up on reload if I don’t insert it.
The only thing I can think of to fix it, is to make a separate instance of the variable which I can then use, but with that it’ll still point to the external variable.

eg. local player = exmodule.player [import]uid: 40538 topic_id: 12819 reply_id: 47114[/import]

So is the main issue now that you can’t see the player, or something else?

If it’s the player, try either using toFront() on it, or toBack() on your background if that suits you better. [import]uid: 52491 topic_id: 12819 reply_id: 47152[/import]

If I “insert” the player, it crashes, if don’t “insert” it, it works, but you cannot see the player… [import]uid: 40538 topic_id: 12819 reply_id: 47214[/import]

But if you don’t insert it you CAN see the physics body when you turn on hybrid, right? That’s what you said?

Have you tried using toFront() on it as suggested? [import]uid: 52491 topic_id: 12819 reply_id: 47276[/import]

Yes I have tried that, but the reason I can’t see it is because I’m not inserting it in localGroup. [import]uid: 40538 topic_id: 12819 reply_id: 47949[/import]

If you want it on top of everything I believe you should be able to move your entire localGroup toBack, then. :slight_smile: [import]uid: 52491 topic_id: 12819 reply_id: 47955[/import]

That won’t any difference though as the code works flawlessly on the first try - it’s only on the second try that all this is happening.

I think I’m gonna try a different approach… [import]uid: 40538 topic_id: 12819 reply_id: 47958[/import]

Wooooooooooo!

I did it! Sorry for the excitement but I’ve been at it for a week and have been racking my head so much.

I ended up rewriting the whole code and it has turned out more clear - cheetomoskeeto’s tutorials saved the day :slight_smile: [import]uid: 40538 topic_id: 12819 reply_id: 47990[/import]