Whatthefuck wrote:Is there any way to load .lua files in threads? I tried doing require "filename", but it errors out in the thread.
You have to require love.filesystem (and any other love modules you might want to use) in the thread's code.
See the [wiki]love.thread[/wiki] wiki page.
murks wrote:Well, ok, it's just that in the middleclass examples it is assigned to a local variable
MiddleClass-Commons is an extension to middleclass, not a replacement. So you first require middleclass however you would normally, and then you require middleclass-commons after, and the latter only needs to be done once.
But how would I go about requiring middleclass-commons after I required middleclass to a local variable?
Require middleclass-comons to another local variable? To the same? I doubt that any of that would work.
Quick question, learning C++ and just learned about what references can do. Was wondering if Lua has something like that, because I was looking for something like it.
Banana = "fruit"
pantry = {}
pantry.orange = banana --believe it or not, logic does apply here
function rotfood()
pantry.orange = "rotten"
end
But I was the Banana to rot too without directly referencing the banana. I'd like it to be this way... Transfer variable1 to variable2. When variable2 changes, I want variable1 to change. any linking of variables?I'm just trying not to have to more lines of code to transfer the variable1 to variable2 and then from variable2 back to variable1. Possible in Lua?
EDIT:
I'm sorry, that C++ thing doesn't even do that. But I'm still learning. Is there still anyway to accomplish what I explained in the above paragraph?
Last edited by Zilarrezko on Thu Sep 04, 2014 6:40 am, edited 1 time in total.
murks wrote:But how would I go about requiring middleclass-commons after I required middleclass to a local variable?
Require middleclass-comons to another local variable? To the same? I doubt that any of that would work.
As I told you, middleclass-commons doesn't return anything, so don't assign it to anything.
Banana = { "Fruit" }
pantry = { }
pantry.orange = Banana
function rotfood()
pantry.orange[1] = "rotten" -- remember that pantry.ornage is now the table { "Fruit" }, not just a string.
end
-- Banana is now { "rotten" }
murks wrote:But how would I go about requiring middleclass-commons after I required middleclass to a local variable?
Require middleclass-comons to another local variable? To the same? I doubt that any of that would work.
local class = require 'middleclass'
require 'middleclass-commons'
-- just use class
The thing is, you don't need to use MiddleClass-Commons, you just need to make it available for other libraries that you're using. It creates a specific global variable that lets other libraries know it's there, but you don't need to do anything else with it.
something.color = {1, 2, 3, 4} --numbers don't matter
function initObject(target)
return {
target = target
}
end
anObject = initObject(something.color[1])
function object:update(dt) --I know the code doesn't work, I'm just trying to throw a visualization
self.target = dt
end
I'd like it to be that... but it's ending up being...
something.color = {1, 2, 3, 4} --numbers don't matter
function initObject(objtitle, target)
return {
objtitle = objtitle
target = target
}
end
anObject = initObject("insertawesomename", something.color[1])
function object:update(dt) --I know the code doesn't work, I'm just trying to throw a visualization
self.target = dt
self:changevar(self.target)
end
function parentObject:changevar(objtitle, var) --Pretend there's a parent object somewhere
if objtitle == "insertawesomename" then
something.color[1] = var
elseif objtitle == "yay" then
something.Abrahamlincolnwithacoln = var
.........
end
end
Not a huge deal, but requires some more hand work. But do I have to make every value in something.color a table? I guess I could just run a for loop at the beginning of draw... But it's going to be a loooong draw function (almost 200 lines and I'm not even 1/4 the way done yet.). [I bet everyone that tried to help me on that OOP post I made is pretty happy with me and my OOP skills now if they saw my code.]
murks wrote:But how would I go about requiring middleclass-commons after I required middleclass to a local variable?
Require middleclass-comons to another local variable? To the same? I doubt that any of that would work.
local class = require 'middleclass'
require 'middleclass-commons'
-- just use class
The thing is, you don't need to use MiddleClass-Commons, you just need to make it available for other libraries that you're using. It creates a specific global variable that lets other libraries know it's there, but you don't need to do anything else with it.
Thanks Robin, that makes it a bit clearer. I wonder why middleclass-commons isn't part of middleclass in the first place as it is only a couple of lines.
I'm really not sure what you're trying to accomplish, Zilarrezko.
Can you make a new thread and try to explain what kind of functionality you're trying to create? The examples don't really make clear what the outcome of this whole puzzle is supposed to be, so I'm not really sure how to help.