This is still a bit messy and the API will probably change a lot but here is my calculator script for VP version 0.2.9. It has some limitations but it works most of the time
For the display use the following action:
Code: Select all
create name calculator
Code: Select all
create sign;activate notify calculator
Code: Select all
signvalue = ''
val1 = 0
val2 = 0
action = nil
shouldclear = false
function notification(sender, args)
local str = sender:description()
local num = tonumber(str)
if num == nil then
if str == 'CE' then
signvalue = ''
action = nil
setsign()
elseif str == '*' then
setvalue()
action = function() signvalue = val1*val2 end
shouldclear = true
elseif str == '/' then
setvalue()
action = function() signvalue = val1/val2 end
shouldclear = true
elseif str == '-' then
setvalue()
action = function() signvalue = val1-val2 end
shouldclear = true
elseif str == '+' then
setvalue()
action = function() signvalue = val1 + val2 end
shouldclear = true
elseif str == '=' then
setvalue()
action()
setsign()
action = nil
shouldclear = true
end
else
if shouldclear then
signvalue = ''
shouldclear = false
end
signvalue = signvalue .. str
setsign()
end -- if num == nil
end
function setvalue()
if action == nil then
val1 = tonumber(signvalue)
else
val2 = tonumber(signvalue)
end
end
function setsign()
this:settexture(SignTexture:new(string.format("%8s",signvalue), 'FFFFFF', '000000'))
end