English timer command

14 replies
Goto Page
To the start Previous 1 Next To the start
15.07.12 10:25:10 pm
Up
Zurak
User
Offline Off
i cant figure out how to correctly use the timer command:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function betlock()
          betable = false
          msg("team bidding is now locked")
     end

     function startround(mode)
          betable = true
          timer(''..(1000)..','..betlock()..'')
          if mode == 50 then
               winner = 1
          elseif mode == 51 then
               winner = 2
          end
     end

error : attempt to concatenate a nil value
when i start the server the startround function doesn't even run and then when i restart the betlock function that is supposed to run 10 seconds later it runs instantly. am i doing something wrong?
edited 1×, last 15.07.12 10:27:58 pm
15.07.12 10:26:20 pm
Up
krabob
User
Offline Off
Code:
1
timer(1000,betlock)
People help the people
15.07.12 10:28:19 pm
Up
EngiN33R
Moderator
Offline Off
The first argument to timer() is a number that is the time in milliseconds. The second argument is a string that is the function name, the third is the argument to that function, and the fourth is a number that is the number of repetitions.

user krabob has written:
Code:
1
timer(1000,betlock)

Code:
1
timer(1000,"betlock")
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
15.07.12 10:35:31 pm
Up
Zurak
User
Offline Off
thank you, but if there is a parameter for the function how would i be able to put it?
edited 1×, last 18.07.12 05:17:42 am
18.07.12 05:20:04 am
Up
PyKemis
User
Offline Off
It is placed on the third parameter.

ex.

Code:
timer(1000,"betlock",5)
18.07.12 07:20:14 am
Up
Zurak
User
Offline Off
what if there is more than 1 parameter but like 5?
18.07.12 08:28:00 am
Up
PyKemis
User
Offline Off
Sorry then you will need to parse lua.

Example:

Code:
1
2
3
4
5
function addNumbers(number1,number2,number3)
     msg(number1+number2+number3)
end

timer(1000,"parse","lua addNumbers(2,3,10)")


That should message '15'.
18.07.12 05:36:45 pm
Up
Zurak
User
Offline Off
ah okay thanks, wish they had this in the cs2d help..
18.07.12 05:48:06 pm
Up
Alistaire
User
Offline Off
user Zurak has written:
ah okay thanks, wish they had this in the cs2d help..


http://www.cs2d.com/help.php?luacat=timer
IMG:http://i.imgur.com/5zhwOTP.png
18.07.12 06:09:31 pm
Up
DC
Admin
Offline Off
Well, here you go. Added some samples to the command reference.
See cs2d lua cmd timer

@user Zurak: Please note the following. It's a common mistake made by people who don't really understand all that ' and " and .. stuff:
• .. connects strings in Lua
• '' (two ' without anything between them) is an empty string without any content

This means that
Code:
1
EXPRESSION..''
or
Code:
1
EXPRESSION..''..EXPRESSION
or
Code:
1
''..EXPRESSION

NEVER EVER makes any sense. You attach an empty string this way. This means you change NOTHING by doing it. It's always 100% pointless in every possible situation. It only changes something if there is something between the two '!
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
18.07.12 06:25:49 pm
Up
Zurak
User
Offline Off
hmm...but is this possible with multiple parameters in the timer function?
Code:
1
2
3
4
5
6
7
function example(a,b)
     timer(1000,"parse","lua example2(a,b)",0)
end

function example2(a,b)
     some code
end
18.07.12 06:41:50 pm
Up
DC
Admin
Offline Off
This might actually work, yes. But you need to be careful with variables and quotes.

Line 2 should be:
Code:
1
timer(1000,"parse",'lua "example2('..a..','..b..')"',0)

So the timer will execute the Lua cs2d lua cmd parse function with parameter
Code:
1
lua "example2(valueOfa,valueOfb)"

And afterwards the CS2D command cs2d cmd lua will execute the code which is given as parameter in double quotes:
Code:
1
example2(valueOfa,valueOfb)
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
18.07.12 07:04:51 pm
Up
Zurak
User
Offline Off
Quote:
'lua "example2('..a..','..b..')"'

a bit of a mindfuck, but works :D, thanks.
19.07.12 08:56:32 am
Up
Infinite Rain
Reviewer
Offline Off
DC Why didn't u made this function like: timer(time, function)?

It would be much easier:
timer(100, addhook('join', 'join_hook'))
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
19.07.12 09:52:27 am
Up
PyKemis
User
Offline Off
@user Infinite Rain: That would never work because you're calling the function when you send it, that would only return a value and from the c standpoint it can't hand anything.

On the other hand, if you use file cs2d Anonymous functions (1) then your script could be:

Code:
timer(100, function()
               addhook('join', 'join_hook')
          end
)
To the start Previous 1 Next To the start