Page 1 of 1

how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 2:41 pm
by velojun
how do i script to increment and decrement a counter using lua?
I cant find any example of this .......

Re: how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 2:48 pm
by Magus
Do you want a counter written in lua or do you want to change the counter with lua?
if you want to change a counter with lua use the functions for counters:

Code: Select all

Counter:increment()
Increments the value of the counter by 1.

Counter:decrement()
Decrements the value of the counter by 1.

Re: how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 3:13 pm
by velojun
I tried:
function blueGems()
if rightBlueGem == "true" or leftBlueGem == "true" then
counter_4:decrement()
end
end

and it worked ( using conectors to the eyesockets)

Re: how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 3:25 pm
by Akatana
counter_4:decrement() :)

e: fu too late ._.

Re: how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 3:26 pm
by velojun
yeah i forgot to place connectors....

Re: how to decrement/increment a counter using script

Posted: Sun Sep 16, 2012 7:59 pm
by Komag
There is also another alternative in the code:

example by petri

Code: Select all

counter = 2

function activate()
  counter = counter - 1
  checkValue()
end

function deactivate()
  counter = counter + 1
  checkValue()
end

function checkValue()
  if counter == 0 then
    door:open()
  else
    door:close()
  end
end
I presume with this method you could have the counter go up or down more than 1 if you wanted, such as "counter + 3", which could be very useful in certain circumstances