我如何在 Corona 和 Lua 中使用“ id = tostring(i) ”
how can i use " id = tostring(i) " in Corona and Lua
我最近看到了这样的东西
if(ebasRating_Arr[i] == 0) then
radioButton_0 = widget.newSwitch {
left = 565,
style = "radio",
initialSwitchState = true,
id = tostring(i),
width = 60,
height = 60,
onPress = setEBASRating0
}
radioGroup:insert( radioButton_0 )
radioButton_1 = widget.newSwitch {
style = "radio",
id = tostring(i),
initialSwitchState = false,
width = 60,
height = 60,
onPress = setEBASRating1
}
radioGroup:insert( radioButton_1 )
注意第 6 行和第 13 行中的 "id = tostring(i)"。所以我正在试验这个 id = tostring(i) 想找出它的含义。有人能告诉我它的真正含义吗?所以我的问题的第二部分如何在我的代码中使用像 id = tostring(i) 这样的东西
local madrs = display.newGroup()
local function textListener( event )
if ( event.phase == "began" ) then
elseif ( event.phase == "ended" or event.phase == "submitted" ) then
-- Output resulting text from "defaultField"
print( event.target.text )
elseif ( event.phase == "editing" ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
i 是 for 循环中的一个数字 你 used.The 按钮的 id 应该在 string 格式,以便 corona sdk 将其识别为 name 之类的 scenes.Example
composer.gotoScene("level"..tostring(event.target.id),{effect="fade"});
上面一行转到了一个名为level1的场景,如果按钮的id是1.It不应该是一个整数或者float.It应该是一个字符串,这样corona sdk会把它当作场景的 名称
兄弟,我不明白你的问题或第二个代码(因为我还没有了解单选按钮),但让我分享我所知道的....说你想知道 radioButton_0 并将其转换为 number.The 代码如下
print(radioButton_0.id); --> prints a string (0) --
print(tonumber(radioButton_0.id));--> prints a number (0)
我不懂无线电buttons.If你告诉我你上面代码的动机(应用),我可以帮助
我最近看到了这样的东西
if(ebasRating_Arr[i] == 0) then
radioButton_0 = widget.newSwitch {
left = 565,
style = "radio",
initialSwitchState = true,
id = tostring(i),
width = 60,
height = 60,
onPress = setEBASRating0
}
radioGroup:insert( radioButton_0 )
radioButton_1 = widget.newSwitch {
style = "radio",
id = tostring(i),
initialSwitchState = false,
width = 60,
height = 60,
onPress = setEBASRating1
}
radioGroup:insert( radioButton_1 )
注意第 6 行和第 13 行中的 "id = tostring(i)"。所以我正在试验这个 id = tostring(i) 想找出它的含义。有人能告诉我它的真正含义吗?所以我的问题的第二部分如何在我的代码中使用像 id = tostring(i) 这样的东西
local madrs = display.newGroup()
local function textListener( event )
if ( event.phase == "began" ) then
elseif ( event.phase == "ended" or event.phase == "submitted" ) then
-- Output resulting text from "defaultField"
print( event.target.text )
elseif ( event.phase == "editing" ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
i 是 for 循环中的一个数字 你 used.The 按钮的 id 应该在 string 格式,以便 corona sdk 将其识别为 name 之类的 scenes.Example
composer.gotoScene("level"..tostring(event.target.id),{effect="fade"});
上面一行转到了一个名为level1的场景,如果按钮的id是1.It不应该是一个整数或者float.It应该是一个字符串,这样corona sdk会把它当作场景的 名称
兄弟,我不明白你的问题或第二个代码(因为我还没有了解单选按钮),但让我分享我所知道的....说你想知道 radioButton_0 并将其转换为 number.The 代码如下
print(radioButton_0.id); --> prints a string (0) --
print(tonumber(radioButton_0.id));--> prints a number (0)
我不懂无线电buttons.If你告诉我你上面代码的动机(应用),我可以帮助