Forum

> > CS2D > Scripts > [Tibia] Timer crashes CS2D
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Tibia] Timer crashes CS2D

19 replies
To the start Previous 1 Next To the start

old [Tibia] Timer crashes CS2D

NeverLast
User Off Offline

Quote
Hello,
If the timer start the code then cs2d close without error's

1
timer (5000, "PLAYERS[id].tmp.atk = PLAYERS[id].tmp.atk - 5")

Admin/mod comment

Fixed the title slightly. /Engi

old Re: [Tibia] Timer crashes CS2D

NeverLast
User Off Offline

Quote
It's the Tibia Script by Weiwen -.-
and when i delete the 2 " then come this error:
1
LUA ERROR: sys/lua/cs2dtibia/items.lua:90: ')' expected near '='

old Re: [Tibia] Timer crashes CS2D

Infinite Rain
Reviewer Off Offline

Quote
I don't what are you trying to say... but I think that you can fix the error by removing the space between the function name and the brackets.

old Re: [Tibia] Timer crashes CS2D

UnkN
User Off Offline

Quote
1
timer (5000,"lua", "PLAYERS[".. id.."].tmp.atk = PLAYERS[".. id.."].tmp.atk - 5")
Have fun^_^
edited 1×, last 14.04.14 07:34:44 pm

old Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Quote
timer (5000, "decreaseattack", id)

function decreaseattack (id)
	PLAYERS[id].tmp.atk = PLAYERS[id].tmp.atk - 5
end

or
timer (5000, "parse", "lua \"PLAYERS[" .. id .. "].tmp.atk = PLAYERS[" .. id .. "].tmp.atk - 5\"")

old Re: [Tibia] Timer crashes CS2D

XoOt
Super User Off Offline

Quote
@user RisingXD:
I just knew the problem of that topic by just reading the title, so whats the matter aboit it.
Ontopic - this is what happens when you try to make another bad tibia edit.

old Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Quote
cozen's script only works if 'id' is a string. It won't work when id is a number, in which case you will have to make it a string.

old Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Quote
@user Torque: It's completely not true. user DC's function read both number and string which case you can call something without changing the number's type to string. Just test this.
test = {}
test[1] = 0
test[2] = 1

timer (0, "parse", "lua \"test[" .. (1) .. "] = test[" .. (2) .. "]\"")

for key, value in ipairs (test) do
	print ("test[" .. key .. "] = " .. value)
end

old Re: [Tibia] Timer crashes CS2D

Conscience
User Off Offline

Quote
Just a little note, it would be a lot easier if you didn't use any spaces in a timer so you don't have to use \"<stuff>\" all the time..

old Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Quote
EDIT: This info was false sorry for almost misinforming you.

Cozen in your example you are still passing a string parameter to the function parse. If you don't pass a string parameter "p" it will get recognised as the count value c. As described in the info.

info.txt has written
[Timer]
- timer(time,"func",["p"],[c])     Create a timer which will call the Lua function "func" after a
                    certain time in milliseconds (time).
                    Moreover it can pass a string parameter (p) to this function.
                    The timer calls the function once by default. However you can call
                    it several times by entering a count value (c). Using 0 or lower
                    count values will make the timer call the function infinite times.


I was trying to possibly save you guys some time because just a few days ago I did this wrong myself.
edited 1×, last 16.04.14 01:29:09 pm

Admin/mod comment

Removed more-tag. /DC

old Re: [Tibia] Timer crashes CS2D

EngiN33R
Moderator Off Offline

Quote
user Dousea has written
@user Torque: It's completely not true. user DC's function read both number and string...

I think you misunderstood user Torque's point - your first script would have to have a tonumber() conversion in the decreaseattack() function, since PLAYERS[id] requires id to be a number. The second script should work as-is.

old Re: [Tibia] Timer crashes CS2D

MikuAuahDark
User Off Offline

Quote
@user Torque: Maybe i don't understand you correctly but LUA insert the arguments in order.

1
2
3
4
5
6
function someexample(id)
	id=tonumber(id)	-- Number-To-String conversion caused by timer
	msg2(id,"Hi!")
end

timer(5000,"someexample",id)
Code above would call function someexample with parameter(first argument) is id(some player ID). But in function someexample, id is string. So just simple, user Dousea code would work fine with(out) error (because the number-to-string conversion).

And one more note: it would never jump to count parameter.

You can try it if you still doesn't believe.

old Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Quote
@user Torque, @user EngiN33R: Just try this, this function works perfectly without any "string-to-number" conversion.
1
2
3
4
5
6
7
8
9
addhook ("join", "joinhook")

function joinhook (id)
	timer (5000, "sayhello", id)
	
	function sayhello (id)
		msg2 (id, "Hello, " .. player (id, "name"))
	end
end

old Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Quote
Ah you guys are right and I was wrong. What caused my confusion was that 'p' gets passed as a string. If you are under the assumption that you are going to receive a number (like I was) that can cause problems.
I think... I'm not sure about anything now anymore

old Re: [Tibia] Timer crashes CS2D

EngiN33R
Moderator Off Offline

Quote
user Dousea has written
@user Torque, @user EngiN33R: Just try this, this function works perfectly without any "string-to-number" conversion.


Well yes, this one does because msg2 is a built-in CS2D function, and they treat strings and numbers for IDs equally. I suggest you try this:

1
2
3
4
5
6
7
8
9
10
11
12
tbltest = {1,2,3}

print("Table value "..tbltest[1].." at index 1") -- Output: Table value 1 at index 1

function testfunc(a)
	tbltest[a] = 0
end

timer(1000, "testfunc", 1)

print("Table value "..tbltest[1].." at index 1") -- Output: Table value 1 at index 1
print("Table value "..tbltest["1"].." at index '1'") -- Output: Table value 0 at index '1'

old Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Quote
@user EngiN33R: Seems yours have an error there. Can't call tbltest["1"] and causing this:
attempt to concatenate field '1' (a nil value)

But you're right, the value of tbltest[1] still 1. I tested my own by checking the type of "index".
function checktype (index)
	print (type (index)) -- Print: "string"
end

timer (1000, "checktype", 1)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview