2

not sure did anyone ever face this kind of problem. here is my code

in main.lua :

local highScore = require("highScore")
local username = "myName"
local finishedTime = 12345

highScore:InsertHighScore(userName, finishedTime)

in highScore.lua

function InsertHighScore(name,time)
   print(name)
   print(time)
   -- other code
end

it look simple and shouldn't be wrong, but in my console out put it show :

 table: 0x19e6340
 myName

after a day of testing, i found that before the 2 parameter that i pass, it actually passing another table to me, so do these changes on highScore.lua:

function InsertHighScore(table,name,time)
   print(table)
   print(name)
   print(time)
   -- other code
end

so now my "other code" can work nicely, but why it pass me a table before my parameter ?

1 Answer 1

4

In Lua, a call to an object/table with a colon instead of a dot indicates that the object/table should be passed into the function as the first parameter (e.g, as a self). If you don't care about that, then call the function with a dot instead:

highScore.InsertHighScore(userName, finishedTime)
Sign up to request clarification or add additional context in comments.

4 Comments

ok... so now i see the problem, so the dot doesn't mean it's accessing a parameter of the class instead of calling the function ?
anyway, thx for your fast and clean reply duskwuff, really appreciate for your help, thank you =)
Accessing a parameter and calling a function are the same thing, actually. highScore.InsertHighScore gets the function as a parameter, adding the parentheses calls it.
table:func(arg1, arg2) is syntactic sugar for table.func(table, arg1, arg2)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.