SetSignLines does not work
#1
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>()
Reply
Thanks given by:
#2
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
Reply
Thanks given by:
#3
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.
Reply
Thanks given by:
#4
Is it not 0-3 ? instead 1-4 ?
Reply
Thanks given by:
#5
Try this:
local IsValid, Line1, Line2, Line3, Line4 = World:GetSignLines(PosX, PosY, PosZ)
Reply
Thanks given by:
#6
(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)
Reply
Thanks given by:
#7
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.
Reply
Thanks given by:
#8
Ahele, se stim smiƙ? Smile
Reply
Thanks given by:
#9
@xoft The function also returns at first position a IsValid variable. The lines would then start at index 2.
Reply
Thanks given by:
#10
Yea, that's right.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)