멋진 커뮤니티 인 것처럼 보이기 때문에이 커뮤니티에 가입했습니다. 새로운 코더이기 때문에 좋은 커뮤니티의 조언을 따라 가면서 신속하게 개선하고 싶습니다. :)루아의 조건부 분기가 명확한 이유없이 작동하지 않습니까?
필자는 lua에서 코딩과 관련하여 질문이 있습니다. 현재 Corona SDK와 Sublime Text 3를 사용하여 모바일 스플래시 화면과 제목 화면을 코딩하고 있습니다. 먼저 titleScreen = false로 시작하여 사실이되게 할 스플래시 화면의 코드를 실행할 수 있습니다. 그러나, 스플래시 화면의 코드를 실행하고 titleScreen = true로 만들면 titlescreen의 조건부 분기가 작동하지 않습니다! 내가 테스트 톤을했습니다 :(도와,하지만 내 오류가 자리하고있는 곳을 알아낼 수 없습니다 제발 여기
내 코드입니다. 어떤 도움이 많이 감사합니다titleScreen = false
local logo = display.newImage("logo.png", 155, 275)
logo.alpha = 0
local function makeMenuTrue()
logo:removeSelf()
print("menu should be TRUE")
print("WHY DOESN'T IT WORK")
titleScreen = true
end
local function fadeOut()
transition.to(logo, {time = 2000, alpha = 0, onComplete = makeMenuTrue})
end
transition.to(logo, {time = 2000, alpha = 1, onComplete = fadeOut})
if (titleScreen == true) then
print("NOW IT'S TRUE")
local mainTheme = audio.loadSound ("mainTheme.wav")
audio.play(mainTheme)
display.setStatusBar(display.HiddenStatusBar)
local background1 = display.newImage("Title.png", 155, 275)
local flare = display.newImage("flare2.png", 40, 30)
flare.xScale = .5
flare.yScale = .5
local flare2 = display.newImage("flare2.png", 400, 70)
flare2.xScale = .6
flare2.yScale = .6
local flare3 = display.newImage("flare2.png", 400, 70)
flare2.xScale = .4
flare2.yScale = .4
local function moveFlare1()
transition.to(flare, {time=2000, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare1})
end
local function moveFlare2()
transition.to(flare2, {time=2000, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare2})
end
local function moveFlare3()
transition.to(flare3, {time=2000, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare3})
end
transition.to(flare, {time=2000, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare1})
transition.to(flare2, {time=2500, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare2})
transition.to(flare3, {time=2000, x = math.random(-100, 450), y = math.random(-100, 700), onComplete = moveFlare3})
--[[local textbox = display.newRect(160, 214, 320, 90)
textbox:setFillColor(.1, .1, .1, .6)
]]
local textbox = display.newImage("MessageBack2.png", 155, 254, 320, 90)
textbox.yScale = .7
local textline = display.newImage("flare2.png", 0, 228)
textline.xScale = 20
textline.yScale = .3
local textOption = 1
local prompt1 = display.newText ("Start Game", 155, 230, "Goudy Old Style", 20)
local prompt2 = display.newText ("Continue", 155, 255, "Goudy Old Style", 20)
local prompt3 = display.newText ("Exit Game", 155, 280, "Goudy Old Style", 20)
prompt1:setFillColor(0,0,0)
local function textShrink()
transition.to(textline, {time = 150, yScale = .3})
end
local function moveTextBox()
if (textOption == 1) then
textOption = 2
transition.to(textline, {time = 200, y = 253, onComplete = textShrink})
prompt2:setFillColor(0,0,0)
prompt1:setFillColor(1,1,1)
else
if (textOption == 2) then
textOption = 3
transition.to(textline, {time = 200, y = 278, onComplete = textShrink})
prompt3:setFillColor(0,0,0)
prompt2:setFillColor(1,1,1)
else
if (textOption == 3) then
textOption = 1
transition.to(textline, {time = 200, y = 228, onComplete = textShrink})
prompt1:setFillColor(0,0,0)
prompt3:setFillColor(1,1,1)
end
end
end
end
local function expandText()
if (textOption == 1) then
print("object 1 has been tapped????")
else
if (textOption == 2) then
print("object 2 has been tapped????")
else
if (textOption == 3) then
print("object 3 has been tapped????")
end
end
end
end
transition.to(textline, {time = 150, yScale = .5, 0, onComplete = moveTextBox})
textbox:addEventListener("tap", expandText)
else
print("lmao no it's not true")
end
!
'transition.to()'는 스크립트가 실행될 때 호출되며, 완료시'fadeOut()'을 호출하고 완료시'makeMenuTrue()'를 호출합니다. –
'makeMenuTrue'가 호출됩니다. 그러나'if' 문은 스크립트가 다시로드 될 때까지 호출되지 않을 것이고'fadeout()'호출 후에 다시로드된다면 스크립트의 맨 처음에'titleScreen'이 지워질 것입니다. – Vlad
우와, 고마워! 나는 "onComplete"를 사용하여 한 쌍의 전환 후에 "makeMenuTrue"를 한 번 호출했지만, 왜 그것이 사실인지 알 수 있습니다. "언제/다시로드/실행하면 titleScreen = false가 무조건 실행되므로 이전 makeMenuTrue 호출로 업데이트 할 수있는 정보를 저장하는 titleScreen을 가질 수 없습니다"라는 부분에 대한 자세한 사양을 요청할 수 있습니까? 나는 그것을 이해하지 못한다. false로 실행 된 값이 makeMenuTrue 호출을 업데이트해서는 안된다. 그것을 막는 것은 무엇입니까? 죄송합니다. 이해가 안되면이 포럼의 언어가 때로는 복잡합니다 :) –