Discord
Login
Community
DARK THEME

class and the toString() method

This code is not working as expected.

Function 'toString ()' - returns an object instead of a string.

Test = class
    constructor = function()
            this.value = 5
    end
    toString = function()
            return " This is the value of the variable value " + value.toString()
    end
    toStr = function()
            return " This is the value of the variable value " + value.toString()
    end
end

init = function()
  test = new Test()
  print( " call test.toString()  result >> "+test.toString() )
  print( " call test.toStr()     result >> "+test.toStr() )
end

update = function()
end

draw = function()
end

I'm guessing 'toString' is reserved (and seemingly functional) but undocumented, so not a bug as such:

init = function()
end

update = function()
end

draw = function()
  n=77
  screen.drawText(n.toString(),0,0,12,"rgb(255,0,0)")
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community