Steamをインストール
ログイン
|
言語
简体中文(簡体字中国語)
繁體中文(繁体字中国語)
한국어 (韓国語)
ไทย (タイ語)
български (ブルガリア語)
Čeština(チェコ語)
Dansk (デンマーク語)
Deutsch (ドイツ語)
English (英語)
Español - España (スペイン語 - スペイン)
Español - Latinoamérica (スペイン語 - ラテンアメリカ)
Ελληνικά (ギリシャ語)
Français (フランス語)
Italiano (イタリア語)
Bahasa Indonesia(インドネシア語)
Magyar(ハンガリー語)
Nederlands (オランダ語)
Norsk (ノルウェー語)
Polski (ポーランド語)
Português(ポルトガル語-ポルトガル)
Português - Brasil (ポルトガル語 - ブラジル)
Română(ルーマニア語)
Русский (ロシア語)
Suomi (フィンランド語)
Svenska (スウェーデン語)
Türkçe (トルコ語)
Tiếng Việt (ベトナム語)
Українська (ウクライナ語)
翻訳の問題を報告
boolean laststate = false
boolean button_out = false
if (button_in == true and (button ~= laststate))
then
button_out = not button_out
end
laststate = button_in
function onTick()
inputX = input.getNumber(3)
inputY = input.getNumber(4)
Time = input.getNumber(1)
touch = input.getBool(1)
if touch == nil then return false end
True = toggle and isPointInRectangle(inputX, inputY, 250, 135, 20, 20)
if touch and not t then
toggle = not toggle
t = touch
end
end
function isPointInRectangle( x, y, rectX, rectY, rectW, recth)
return x > 250 and y > 135 and x < 250+20 and y < 135+20
end
function onDraw()
w = screen.getWidth()
h = screen.getHeight()
screen.setColor(0, 255, 0)
screen.drawText(5, 5, 'Time:'..Time)
screen.setColor(255, 0, 0)
screen.drawRectF(250, 135, 20, 20)
if True then
screen.drawLine(w/2, 70, w/2, 90)
screen.drawLine(134, h/2, 154, h/2)
screen.drawCircle(w/2, h/2, 10)
else
screen.drawText(90, h/2, 'Please press the button')
end
end
This is a test on my first lua it does not have a specific purpose just my first try out but i couldn't figure out how to implement your logic into mine
Maybe change that to:
if touch == nil then
toggle = false
return false
end
touch can only be nil when it isn't initialized yet. Otherwise its either true or false.
Here's some solutions:
Straight Code - from Carrot Cake:
Create a touch point on the Screen. The canPress is to alleviate the bouce you get back and forth between On/Off while a key is held.
if isPressed then
if canPress then
out = not out
canPress = false
end
else
canPress = true
end
Alternate solution I put forward with a JK Flip Flop outside of the lua block but still in the microcontroller:
Have a touchscreen spot that you click to toggle, output the results of that (in composite) as Boolean. In the Microcontroller housing your Lua block have a JK Flip Flop and have the output of that Boolean go in to both the set and reset at the same time. Have the result of the JK Flip Flop come back in as an On/Off channel input back to your Lua Block. The result of that input is your toggle. Every time you click on the touchscreen spot it will invert the set of the JK Flip Flop which toggles the value of the input back in to Lua. La voila, toggle in Lua.
Thanks for the explanation. I come from a C background and assumed nil == false.
if isPressed then
if canPress then
out = not out
canPress = false
end
else
canPress = true
end
@ElfBossHogg I think your and mine solution is the most elegant one, to whomever is scrolling through here this is the best solution.
actual code had diff variables, but I put yours because ur variables are far better named. I named canPress "t" for no reason.