Search found 12 matches

by Davïd
Tue Dec 19, 2017 6:08 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Re: Lua access parent scope var with same name as in local scope ?

The plan was to groupe gameobject by type, for example : - gameobject -- character --- player --- monster player will inherit fields and methods from character and so on for gameobject. - gameobject will contain basic stuff like x y position in world maybe an ID - character will contain a component ...
by Davïd
Mon Dec 18, 2017 6:50 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Re: Lua access parent scope var with same name as in local scope ?

Ok, I changed my code with the closure you gave me and it look nicer. :nyu:

I tried some example with metatable but to me it look over complicated. Also I think it better fit with real OOP (with multiple inheritance and stuff like that) but I m not sure for oriented prototype code ?
by Davïd
Sun Dec 17, 2017 7:45 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Re: Lua access parent scope var with same name as in local scope ?

I already read about metatable but I wont get why they are needed and how do they work for now. I will get back to it.

Thank you.
by Davïd
Sun Dec 17, 2017 4:46 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Re: Lua access parent scope var with same name as in local scope ?

Your code looks fine, note that if you want to do OO using closures you can just return a function and you don't need to use self or the colon operator(":") return function(id) local _x, _y = 0, 0 local obj = {} function obj.set(x, y) _x, _y = x, y end function obj.get() return _x, _y end...
by Davïd
Sun Dec 17, 2017 3:23 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Re: Lua access parent scope var with same name as in local scope ?

Ok so it's not possible. I will go with _ prefix then. Some people does that in other laguages too. I was wondering cause it's also used for throw away vars like in for _,v in ipairs(t) do print(v) end @drunken_munki To me xPosition is an object private field and I feel more natural to put everythin...
by Davïd
Sun Dec 17, 2017 1:30 pm
Forum: Support and Development
Topic: Lua access parent scope var with same name as in local scope ?
Replies: 11
Views: 6613

Lua access parent scope var with same name as in local scope ?

Hello, is there some way to access some var in parent scope var with same name as in local scope ? A small example: local xPosition -- Parent scope Var function setPosition(xPosition, yPosition) xPosition -- Access local var -- How to access parent scope xPosition ? end If it isn't possible I think ...
by Davïd
Sat Nov 04, 2017 12:53 pm
Forum: Support and Development
Topic: Delete an object
Replies: 3
Views: 10610

Re: Delete an object

Ok thank you. I'm used to languages where you can juste delete an object like PHP. I will look at weak table. The idea behind gameObjectList is to call an update() method for each gameobject and I also plan to have other lists like a monster table for example. When a monster die I need to remove it ...
by Davïd
Sat Nov 04, 2017 10:54 am
Forum: Support and Development
Topic: Delete an object
Replies: 3
Views: 10610

Delete an object

Hello everyone. Quite noob question but here is something I couldn't get. I have an object which look like this : local Object = {} --[[ Object definition @return table : new Object ]] function Object.new() local self = require('script.object.gameobject').new() --[[ Privates vars -------------------...
by Davïd
Mon Sep 25, 2017 6:12 pm
Forum: Support and Development
Topic: Require path
Replies: 3
Views: 3428

Re: Require path

Thanks for answers. I changed structure like Grump suggested.

And I didn't know about init files. Thank you for such quality answer Davis.
by Davïd
Sun Sep 24, 2017 1:55 pm
Forum: Support and Development
Topic: Require path
Replies: 3
Views: 3428

Require path

Hello, I have the following folder structure : /classes classes.lua --/data --/data.lua --/components --/components.lua ----/movement ----/movement.lua you get the idea. And I wonder if there is a way to require file like this require('classes.components.movement') instead of : require('classes.comp...