Forum

> > CS2D > Scripts > [Tibia] Timer crashes CS2D
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [Tibia] Timer crashes CS2D

19 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt [Tibia] Timer crashes CS2D

NeverLast
User Off Offline

Zitieren
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 Kommentar

Fixed the title slightly. /Engi

alt Re: [Tibia] Timer crashes CS2D

NeverLast
User Off Offline

Zitieren
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 '='

alt Re: [Tibia] Timer crashes CS2D

UnkN
User Off Offline

Zitieren
1
timer (5000,"lua", "PLAYERS[".. id.."].tmp.atk = PLAYERS[".. id.."].tmp.atk - 5")
Have fun^_^
1× editiert, zuletzt 14.04.14 19:34:44

alt Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Zitieren
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\"")

alt Re: [Tibia] Timer crashes CS2D

XoOt
Super User Off Offline

Zitieren
@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.

alt Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Zitieren
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.

alt Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Zitieren
@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

alt Re: [Tibia] Timer crashes CS2D

Conscience
User Off Offline

Zitieren
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..

alt Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Zitieren
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 hat geschrieben
[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.
1× editiert, zuletzt 16.04.14 13:29:09

Admin/Mod Kommentar

Removed more-tag. /DC

alt Re: [Tibia] Timer crashes CS2D

EngiN33R
Moderator Off Offline

Zitieren
user Dousea hat geschrieben
@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.

alt Re: [Tibia] Timer crashes CS2D

MikuAuahDark
User Off Offline

Zitieren
@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.

alt Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Zitieren
@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

alt Re: [Tibia] Timer crashes CS2D

Torque
User Off Offline

Zitieren
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

alt Re: [Tibia] Timer crashes CS2D

EngiN33R
Moderator Off Offline

Zitieren
user Dousea hat geschrieben
@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'

alt Re: [Tibia] Timer crashes CS2D

Dousea
User Off Offline

Zitieren
@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)
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht