sorry but how do you this ? too difficult to discribe

hi everybody but i can’t do my function returnTheNumberOfTheLevel(currentlevel)

this works  returnTheNumberOfTheLevel(1) but i want this returnTheNumberOfTheLevel(currentlevel)

What’s the solution and why doesn’t it work?

thanks

--LEVEL local level = {} level[1] = {} level[1].playersbegin = 2 level[1].playermax = 3 level[1].time = 60 level[1].textLevelPrecision = "funny Level" level[1].countTap = 4 level[1].Background = "back01.png" level[1].difficulty = 0.25 --to 0.9 more difficult level[1].special = 0 level[2] = {} level[2].playersbegin = 8 level[2].playermax = 3 level[2].time = 60 level[2].textLevelPrecision = "level de fou" level[2].countTap = 1 level[2].Background = "back02.png" level[2].difficulty = 0.3  --to 0.9 more difficult level[2].special = 0 local textNumberLevel = display.newText(myGrouptext, "", 100,100, fontLuckiest, 25) textNumberLevel:setFillColor(1,1,1) textNumberLevel.text = 1 textNumberLevel.anchorX = 0 local currentLevel = print(textNumberLevel.text) local function returnTheNumberOfTheLevel(d) b = level[d].time c = level[d].textLevelPrecision difficulty = level[d].difficulty e = level[d].special countTap = level[d].countTap imageBackground = level[d].Background playersbegin = level[d].playersbegin playermax = level[d].playermax textLevelPrecision.transition = transition.to(textLevelPrecision,{alpha = 0,time=700,transition= easing.inOutBounce, delay=2000} ) textLevelText.transition = transition.to(textLevelText,{alpha = 0,time=700,transition= easing.inOutBounce, delay=2000} ) return b,c,e,countTap, playersbegin, imageBackground, playermax, difficulty end returnTheNumberOfTheLevel(currentlevel)

You are setting the variable “currentLevel” =  to a print text function, rather than to a number.

Also, you are using an undefined variable “currentlevel” when you call the function returnTheNumberOfTheLevel.  You probably meant to use “currentLevel”.  Those are two different variables since one uses the capital L.

hi Stephen Lewis,

for the capital is a typo. in my snippet it’s alright 

returnTheNumberOfTheLevel(currentLevel)

i have tried this but it’s don’t worked :

local currentLevel = textNumberLevel.text

while

print("currentLevel", currentLevel)

return

currentLevel 1

any suggestions ?

It looks like what you are trying to do is set the text string parameter of a display.newText object to be the number 1.    

textNumberLevel.text = 1

But you can’t do that.  The .text parameter of a newText object is supposed to be a string, so setting it to 1 is actually setting it to “1”.  (The string “1”, not the number 1).   Lua has a fancy trick of automatically converting a number to a string if it is expecting a string.  

You can check that by printing the type of the variable using a line like:

print(type(currentLevel))

I’m guessing it will print “string” instead of “number”.

So you are trying to access your table entry at index number 1 using the string “1” which you have not defined.  

A simple fix would be to convert the string to a number when you call your function, like this:

returnTheNumberOfTheLevel(tonumber(currentLevel))

Thanks Stephen Lewis,

Now i know the difference between the string and the number.

II changed my code to avoid this ambiguity and have only numbers. Thank you again for this learning and good day

You are setting the variable “currentLevel” =  to a print text function, rather than to a number.

Also, you are using an undefined variable “currentlevel” when you call the function returnTheNumberOfTheLevel.  You probably meant to use “currentLevel”.  Those are two different variables since one uses the capital L.

hi Stephen Lewis,

for the capital is a typo. in my snippet it’s alright 

returnTheNumberOfTheLevel(currentLevel)

i have tried this but it’s don’t worked :

local currentLevel = textNumberLevel.text

while

print("currentLevel", currentLevel)

return

currentLevel 1

any suggestions ?

It looks like what you are trying to do is set the text string parameter of a display.newText object to be the number 1.    

textNumberLevel.text = 1

But you can’t do that.  The .text parameter of a newText object is supposed to be a string, so setting it to 1 is actually setting it to “1”.  (The string “1”, not the number 1).   Lua has a fancy trick of automatically converting a number to a string if it is expecting a string.  

You can check that by printing the type of the variable using a line like:

print(type(currentLevel))

I’m guessing it will print “string” instead of “number”.

So you are trying to access your table entry at index number 1 using the string “1” which you have not defined.  

A simple fix would be to convert the string to a number when you call your function, like this:

returnTheNumberOfTheLevel(tonumber(currentLevel))

Thanks Stephen Lewis,

Now i know the difference between the string and the number.

II changed my code to avoid this ambiguity and have only numbers. Thank you again for this learning and good day