Is it possible to split code to multiple files?
Example:
I have scene with logic for one level and it starts to be unreadable (too many functions). I can move function to new file (for example Scene:Score) but then I can't access local variables from main scene (i don't want to send that variables when calling function and complicate more things).
I mean, is it possible to have parts of code in multiple files and then when executed it behaves like that all that parts are one file (something like #include in c)?
Sorry for my english, I hope you can undrestand what I'm trying to ask.
Comments
I'm not saying this is the best way to accomplish this but it's what I use and I think it's fantastic.
Usage example:
I also attached full example as Gideros project.
FIXED: chunk concatenation.
Likes: pie
I found that self. variables from scene are passed to all lua files that have code for that scene:
a.lua
function Game:init()
self.a = 5
end
b.lua
function Game:Test()
print(self.a)
end
Question: Are self. variables same as local, are they destroyed when scene closes?
https://deluxepixel.com
In your example: a is a property of Game class.
b.lua contains a method which extends Game class - it prints out its property a.
Properties are destroyed when their owner (object) is destroyed (scenes are Sprite objects, so the answer to your last question is yes) but they are not the same as local vars which are removed as soon as possibile (and are the fastest to access).
I'd say that properties "stay between" global and local vars because you can access them as long as you can access their "object" (Game, using your example).
local g=Game.new ()
g:Test ()
Is the same of
print(g.a)
If you consider any object as a table (it is in lua) a is just an entry of Game table.
Game[a] = self.a (where self is Game)
The only issue I can think of, about splitting code from the same class, is about code dependency: you will have to make sure that every "chunk" of the same class is loaded in the correct order. I believe that loading b.lua before a.lua would return an error.
It would be great if Gideros Studio had stuff like this.
Likes: n1cke
Likes: antix
main.lua:115: bad argument #1 to 'addChild' (Sprite expected, got string)
stack traceback:
main.lua:115: in main chunk
Under the "Project" menu, did you set "Lua Interpreter" to "Gideros"?
I'm still on 1.2 but will upgrade to 1,.3 right now, cheers @n1cke
-Add require("mobdebug").start() line to your main.lua script.
-Select Gideros as an interpreter in ZeroBrane Studio going to Program | Lua Interpreters | Gideros. In addition to enabling debugging, it will also turn on auto-complete for Gideros API calls. If the Gideros player executable is in a default location (/Applications on OSX or C:\Program Files or \Program Files on Windows) or in one of the folders listed in PATH, it will be found by the IDE. If the executable is in a different location, you may need to specify this location in cfg/user.lua file (see cfg/user-sample.lua for details on how this is done).
That's from this page.. http://notebook.kulchenko.com/zerobrane/gideros-debugging-with-zerobrane-studio-ide
Still no luck?
I remember reading somewhere on the forum some time ago that ZBS will support Gideros error messages in an up and coming version. This feature would improve workflow enormously.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Maybe @paulclinger can help, he is the creator of ZB Studio.
@antix, thank you for the ping.
Likes: n1cke
Likes: n1cke
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: antix
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Errors work in development version in all modes (Execute, Debug, Scratchpad), but you need to press "Stop" button to see them (can it be improved?). Also Gideros Studio has to be closed or it will redirect all errors to itself and you will see nothing.
ok, I'll use it to update the list in ZBS then.
> Errors work in development version in all modes (Execute, Debug, Scratchpad), but you need to press "Stop" button to see them (can it be improved?).
Probably can't do much about it, as the output from `gdrbridge getlog` can only be read after the error is thrown, but since the player continues to run, the IDE doesn't know that the error happened. When you "stop" the application, the IDE reads the error from "gdrbridge" and shows it in the Output panel.
Likes: pie, n1cke, antix