Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-16-2016, 12:37 AM
(This post was last modified: 01-16-2016, 12:37 AM by nixi.)
Hi,
I have started using lua yesterday and I just can not get past this problem. I need to update all lines of a specific sign. "World:SetSignLines()" Either does nothing (if called in a function started by a hook) or it throws out an error (if started in an independent function). How can I use this properly?
function poiMain(Split, Player)
World:SetSignLines(58, 64, 42, "test", "test", "test", "test")
return true
end
Code: [15:34:37] LUA: Plugins/PointsOfInterest/functions.lua:52: attempt to index global 'World' (a nil value)
[15:34:37] Stack trace:
[15:34:37] Plugins/PointsOfInterest/functions.lua(52): (no name)
[15:34:37] Stack trace end
[15:34:37] Error in plugin PointsOfInterest calling function <callback>()
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Hello and welcome to the forum.
Your World variable is empty, but you can get it from the player:
function poiMain(Split, Player)
Player:GetWorld():SetSignLines(58, 64, 42, "test", "test", "test", "test")
return true
end
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-16-2016, 02:21 AM
(This post was last modified: 01-16-2016, 02:27 AM by nixi.)
Yes, that works. Thank You.
What if I wanted to GetSignLines and assign Line4 into a variable?
I tried this:
lines = Player:GetWorld():GetSignLines(BlockX, BlockY, BlockZ)
Player:SendMessage(lines[4])
That, of course, did not work.
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
Is it not 0-3 ? instead 1-4 ?
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Try this:
local IsValid, Line1, Line2, Line3, Line4 = World:GetSignLines(PosX, PosY, PosZ)
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-16-2016, 04:08 AM
(This post was last modified: 01-16-2016, 04:12 AM by nixi.)
(01-16-2016, 03:21 AM)ThuGie Wrote: Is it not 0-3 ? instead 1-4 ?
As far as I know, lua starts counting from 1. It does not work even when I change it to 3.
(01-16-2016, 04:06 AM)NiLSPACE Wrote: Try this:
local IsValid, Line1, Line2, Line3, Line4 = World:GetSignLines(PosX, PosY, PosZ)
This works! Tahnk you very much.
My code:
local IsValid, Line1, Line2, Line3, Line4 = Player:GetWorld():GetSignLines(BlockX, BlockY, BlockZ)
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
You'd need to make an array out of the "lines" variable. Lua has bit different syntax rules:
local a, b, c = 1, 2, 3, 4
--> a == 1; b == 2; c == 3; 4 gets forgotten
-- In this same fashion:
local lines = "line1", "line2", "line3", "line4"
--> lines = "line1"; Lua discards "line2" - "line4"
-- You probably want this:
local lines = { World:GetSignLines(PosX, PosY, PosZ) }
--> lines[1] == "line1"; lines[2] == "line2" etc.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Ahele, se stim smiĆ?
Posts: 513
Threads: 10
Joined: May 2014
Thanks: 138
Given 89 thank(s) in 75 post(s)
@ xoft The function also returns at first position a IsValid variable. The lines would then start at index 2.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
|