how to decrement/increment a counter using script

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

how to decrement/increment a counter using script

Post by velojun »

how do i script to increment and decrement a counter using lua?
I cant find any example of this .......
Magus
Posts: 56
Joined: Wed Sep 12, 2012 6:05 pm

Re: how to decrement/increment a counter using script

Post 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.
velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

Re: how to decrement/increment a counter using script

Post 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)
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Re: how to decrement/increment a counter using script

Post by Akatana »

counter_4:decrement() :)

e: fu too late ._.
Last edited by Akatana on Sun Sep 16, 2012 3:26 pm, edited 1 time in total.
velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

Re: how to decrement/increment a counter using script

Post by velojun »

yeah i forgot to place connectors....
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: how to decrement/increment a counter using script

Post 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
Finished Dungeons - complete mods to play
Post Reply