# Coding Help

#### CesarZ

##### Active Member
Hello guys i'm trying to add the "interval" parameter so they can work with different timing.
this script is the Talk-sings script.

Lua:
``````--Normal script.

local t = {
{"", {x = 781, y = 1002, z = 6}, 73},
{"", {x = 777, y = 995, z = 7}, 73},
{"", {x = 777, y = 1001, z = 8}, 73},
{"", {x = 762, y = 1002, z = 7}, 73}
}

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for i = 1, #t do
local v = t[i]
doCreatureSay(people, v, TALKTYPE_ORANGE_1, false, 0, v)
doSendMagicEffect(v, v)
end
return true
end``````

My script that im working on

Lua:
``````local t = {
--{"", {x = 781, y = 1002, z = 6}, 73},
-- {"", {x = 777, y = 995, z = 7}, 73},
--{"", {x = 777, y = 1001, z = 8}, 73},
{"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
{"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
--{"", {x = 762, y = 1002, z = 7}, 73}
}

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for i = 1, #t do
local v = t[i]
doCreatureSay(people, v, TALKTYPE_ORANGE_1, false, 0, v, v) -- v added so it work with interval.
doSendMagicEffect(v, v, v) -- v added so it can work with interval.
end
return true
end``````

the result of this one is = one is working but the other talk-sing is giving me a

attempt to call local 'interval' (a number value) error

let me know what i did wrong im pretty new with lua arrays im trying to learn this.

Solution
this script working fine.

quick question.

Is the function
Code:
``sendAfterDelay(creature, text, position, effect)``
was created by you, or it comes with the other functions in the lua source file?
I saw `addevent` but not this one and i was just wondering how did you get this function.
we are allowed to improvise in these things when it comes to functions?

I created that function, it doesn't exist by default. If you need to create your own functions to organize your code, you can do it.

Lua:
``````function yourFunctionName(parameter1, parameter2 .. etc)
end``````

is there a list other than searching on luascript.cpp for tfs1.3?
Yes, there is: otland/forgottenserver...

#### Snavy

##### Bakasta
Senator
Hello guys i'm trying to add the "interval" parameter so they can work with different timing.
this script is the Talk-sings script.

...

the result of this one is = one is working but the other talk-sing is giving me a

attempt to call local 'interval' (a number value) error

let me know what i did wrong im pretty new with lua arrays im trying to learn this.

Are you trying to send text+effect after some time has passed?

The error you're receiving `attempt to call local 'interval' (a number value)` is telling you that the "function" you're trying to call `interval(v)` is not a function but a number.

In this script that you have, inside onThink function, `interval` is a variable which holds a `number` which is retrieved from globalevents.xml where you have something like `interval="1000"`.
Lua:
``function onThink(interval)``
Since `interval` is a number, you can not use it as a function; `interval()`.

What you need to use here is `addEvent()` function which will allow you to specify what code to execute and when

usage: `addEvent(myFunction, delay, parameters)`

Lua:
``````local t = {
--{"", {x = 781, y = 1002, z = 6}, 73},
-- {"", {x = 777, y = 995, z = 7}, 73},
--{"", {x = 777, y = 1001, z = 8}, 73},
{"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
{"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
--{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v doesn't exist, 1000 will be used.

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for i = 1, #t do
local v = t[i]
local interval = v or defaultInterval

-- call sendAfterDelay function after _interval_ time
addEvent(sendAfterDelay, interval, people, v, v, v)
end

return true
end

function sendAfterDelay(creature, text, position, effect)
doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
doSendMagicEffect(position, effect)
end``````

Last edited:
• Xikini and Levi999x

#### CesarZ

##### Active Member
Are you trying to send text+effect after some time has passed?

The error you're receiving `attempt to call local 'interval' (a number value)` is telling you that the "function" you're trying to call `interval(v)` is not a function but a number.

In this script that you have, inside onThink function, `interval` is a variable which holds a `number` which is retrieved from globalevents.xml where you have something like `interval="1000"`.
Lua:
``function onThink(interval)``
Since `interval` is a number, you can not use it as a function; `interval()`.

What you need to use here is `addEvent()` function which will allow you to specify what code to execute and when

usage: `addEvent(myFunction, delay, parameters)`

Lua:
``````local t = {
--{"", {x = 781, y = 1002, z = 6}, 73},
-- {"", {x = 777, y = 995, z = 7}, 73},
--{"", {x = 777, y = 1001, z = 8}, 73},
{"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
{"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
--{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v doesn't exist, 1000 will be used.

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for i = 1, #t do
local v = t[i]
local interval = v or defaultInterval

-- call sendAfterDelay function after _interval_ time
addEvent(sendAfterDelay, interval, people, v, v, v)
end

return true
end

function sendAfterDelay(creature, text, position, effect)
doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
doSendMagicEffect(position, effect)
end``````

this script working fine.

quick question.

Is the function
Code:
``sendAfterDelay(creature, text, position, effect)``
was created by you, or it comes with the other functions in the lua source file?

I saw `addevent` but not this one and i was just wondering how did you get this function.

we are allowed to improvise in these things when it comes to functions?

is there a list other than searching on luascript.cpp for tfs1.3?

Last edited:

#### Snavy

##### Bakasta
Senator
this script working fine.

quick question.

Is the function
Code:
``sendAfterDelay(creature, text, position, effect)``
was created by you, or it comes with the other functions in the lua source file?
I saw `addevent` but not this one and i was just wondering how did you get this function.
we are allowed to improvise in these things when it comes to functions?

I created that function, it doesn't exist by default. If you need to create your own functions to organize your code, you can do it.

Lua:
``````function yourFunctionName(parameter1, parameter2 .. etc)
end``````

is there a list other than searching on luascript.cpp for tfs1.3?
Yes, there is: otland/forgottenserver (https://github.com/otland/forgottenserver/wiki/Script-Interface)
( not sure if they are finished )

#### StreamSide

##### Joseluis Gonzalez
Support Team
Are you trying to send text+effect after some time has passed?

The error you're receiving `attempt to call local 'interval' (a number value)` is telling you that the "function" you're trying to call `interval(v)` is not a function but a number.

In this script that you have, inside onThink function, `interval` is a variable which holds a `number` which is retrieved from globalevents.xml where you have something like `interval="1000"`.
Lua:
``function onThink(interval)``
Since `interval` is a number, you can not use it as a function; `interval()`.

What you need to use here is `addEvent()` function which will allow you to specify what code to execute and when

usage: `addEvent(myFunction, delay, parameters)`

Lua:
``````local t = {
--{"", {x = 781, y = 1002, z = 6}, 73},
-- {"", {x = 777, y = 995, z = 7}, 73},
--{"", {x = 777, y = 1001, z = 8}, 73},
{"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
{"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
--{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v doesn't exist, 1000 will be used.

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for i = 1, #t do
local v = t[i]
local interval = v or defaultInterval

-- call sendAfterDelay function after _interval_ time
addEvent(sendAfterDelay, interval, people, v, v, v)
end

return true
end

function sendAfterDelay(creature, text, position, effect)
doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
doSendMagicEffect(position, effect)
end``````
cute code

• Levi999x and Snavy

#### CesarZ

##### Active Member
@Snavy Thanks man awesome help.

• Snavy

Replies
4
Views
321
Replies
3
Views
221
Replies
2
Views
194
Replies
0
Views
193
RevScripts Kick Boss Room
Replies
3
Views
217