Problems with Lua and the colon :


#1

I’ve been playing the Lua version of the game and it seems to have a ton of issues. half of the time the reference code is in Java script and usually the functions made as a reference by CodeCombat do not work. I can figure it out and make it work, however it is obviously not supposed to be this way. And it is becoming worse the further i get. Is any of this going to be fixed soon? if not it is a waste of time playing the lua version of the game at a certain point. Because it is teaching incorrect code, at least i think it is. For example:

local = enemy hero.findNearestEnemy() Is Lua script, but this also works

local = enemy hero:findNearestEnemy()

its just a difference in a period verses a semicolon, but that means that the game is teaching that semicolons work in Lua which i dont believe is true. this is my first coding experience however i would like for it to be accurate.


#2

@goku_face Yes, the : is definitely LUA code.

I am very curious which levels you are struggling with. I have been assisting the team with updates to the LUA code. So if there are levels that are not converted that you would like converted please let me know.

From what I understand the LUA updates are part of the community effort. Being a member of the community I just haven’t had time to update them all. I was focusing on updates to any level that was posing an issue in particular. And as time will permit, continue forward until all levels had code.


Definition of :

When we talk about object oriented type programming the : comes into play. Here is a good read about what the : does. http://www.lua.org/pil/16.html

To summarize: when we want to use this or self to allow a function/method to refer to the object passed to it instead of a hard coded name, we can use the : convention. hero:findNearestEnemy() should then be similar to hero.findNearestEnemy(hero)

When making LUA code patches I was following along with the other code in the game, I have been updating the code by using this method. I notice that hero.say() and hero:say() will do similar things as well as hero.moveUp() and hero:moveUp() however when we call hero.findNearestEnemy() it will throw an error. So hero:findNearestEnemy() should be used.

(I have updated the subject for this post to be helpful for other players to find as well because they may be having the same issues. Good questions!)