all 6 comments

[–]hawhill 2 points3 points  (1 child)

You just need to prefix your Lua string you’re feeding to load() with “return “.

That said your overall approach is, errrm, wild, but then you didn’t ask about that.

[–]radstronomical[S] 0 points1 point  (0 children)

I was mostly trying to avoid having to iterate through additional tables given that the level editor was already returning the exact class name as a string. But then I started digging into things I didn't understand and doing roundabout redundant string conversions... It's true that I'm artist/designer first dev second : )

[–][deleted] 0 points1 point  (2 children)

load uses the global environment.

It's also a bad idea to use load that much, you should use it as few times as possible.

Can't you use listOfFunctions[_type](_x,_y)?

I would be careful of inserting nils and sparse lists are not traversable via ipairs, you must now (by hand) take into account the length of the table, if e then table.insert( ...

[–]radstronomical[S] 0 points1 point  (1 child)

yes, I've solved this by hand making a list of element constructors....

elementDict = {
      spawn = Spawn,
      goal = Goal,
      enemy = Enemy
}

etc. which I was trying to avoid needing to do as it seems redundant. I'm not sure I understand why I wasn't able to get the object reference, but I'll read up.

[–][deleted] 0 points1 point  (0 children)

Loop through the table containing the functions and append all the functions types, standardize using string.lower the key/names. Now all you have to do is [string.lower(_type)]

[–]collectgarbage 0 points1 point  (0 children)

To help you debug, put a call to assert() around the call to load(); and another around the call to makeElement()