Jump to content




Problem with a error, A question infact.[Solved]


  • You cannot reply to this topic
9 replies to this topic

#1 libraryaddict

  • New Members
  • 195 posts

Posted 17 May 2012 - 06:31 AM

Im getting the error "Index expected. Got nil" yet I know that the table was defined.
However I defined it locally in the API.

My question is. Can the local table in the API expire or something?

Somehow between this code
function playerJoin(ID, Name)
	ClientsNo[ID] = #Clients+1
	Clients[ClientsNo[ID]] = {}
	Clients[ClientsNo[ID]]["Name"] = Name
	Clients[ClientsNo[ID]]["ID"] = ID
	setPlayerMap(ID, "OrigSpawn")
end

and this code
function screenOptions(Locked, Width, Height, ID)
  Clients[ClientsNo[ID]]["LockedScreen"] = Locked
  Clients[ClientsNo[ID]]["ScreenWidth"] = Width
  Clients[ClientsNo[ID]]["ScreenHeight"] = Height
end

ClientsNo is now empty..

Im calling on them with a API with every table/variable local to the API.

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 17 May 2012 - 06:40 AM

Is the var in the API and you are trying to use it from the program? If so you can not access it from the program.

I do use local vars in my API's and as long as I only use them in the API and not externally from a program I've never had any issues with them staying present as long as the API is loaded.

#3 libraryaddict

  • New Members
  • 195 posts

Posted 17 May 2012 - 06:52 AM

All variables are set in my API.
The program itself just calls on the API.

#4 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 17 May 2012 - 08:41 AM

Without seeing all your api code and such I can't say.
So if you can provide that it will be easier to help.

#5 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 17 May 2012 - 08:44 AM

So it should work, do you have something else in your code that is over writting/resetting the var?

I tried this little simple test and the var was stored and printed out correctly in the 2nd function. Load the first as an API and run the second as a program.
Spoiler


#6 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 17 May 2012 - 08:49 AM

View Postluanub, on 17 May 2012 - 08:44 AM, said:

So it should work, do you have something else in your code that is over writting/resetting the var?

I tried this little simple test and the var was stored and printed out correctly in the 2nd function. Load the first as an API and run the second as a program.
Spoiler

There is no reason/need for you to declare
local var = ""


#7 libraryaddict

  • New Members
  • 195 posts

Posted 17 May 2012 - 09:20 AM

My code then D:
Spoiler

What I used to test it. Minus the API loading. map is the API.
map.setSpawn("mappy", 5, 5)
map.loadMap("mappy", "Darling")
map.setDefault("mappy")
map.playerJoin(666, "Andrew", "mappy")
map.screenOptions("no", 10, 10, 1)

while true do
  event,param1,param2 = os.pullEvent()
  if event == "key" then
	if param1 == 200 then -- up
	  map.moveScreen(1, -1, 1, "mappy")
	  local y = {returnMap(1)}
	  for n=1,#y do
		term.write(y[n])
	  end
	elseif param1 == 208 then -- down
	  map.moveScreen(1, -1, 1, "mappy")
	  local y = {returnMap(1)}
	  for n=1,#y do
		term.write(y[n])
	  end
	elseif param1 == 203 then -- left
	  map.moveScreen(1, -1, 1, "mappy")
	  local y = {returnMap(1)}
	  for n=1,#y do
		term.write(y[n])
	  end
	elseif param1 == 205 then -- right
	  map.moveScreen(1, -1, 1, "mappy")
	  local y = {returnMap(1)}
	  for n=1,#y do
		term.write(y[n])
	  end
	end
  end
end


Pastebin doesnt like me atm :

#8 libraryaddict

  • New Members
  • 195 posts

Posted 17 May 2012 - 09:22 AM

I guess you would want a mappy too..

I just used a thingy to generate code in a 200x200 box.
mappy isn't important. Just needs a file.

Also the stuff after while true do isn't important either.

Also please consider my API is a WIP..
Heh. Just realised my second program had a derp.
But nothing that effected the API..

Also. ClientsNo is the one thats getting reset.

#9 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 17 May 2012 - 11:47 AM

View Postlibraryaddict, on 17 May 2012 - 09:22 AM, said:

I guess you would want a mappy too..

I just used a thingy to generate code in a 200x200 box.
mappy isn't important. Just needs a file.

Also the stuff after while true do isn't important either.

Also please consider my API is a WIP..
Heh. Just realised my second program had a derp.
But nothing that effected the API..

Also. ClientsNo is the one thats getting reset.

And we fixed this in IRC it is worth pointing out - you were setting up one ID and then trying to index the table by another ID - meaning the index in the table was nil, NOT the table.

#10 libraryaddict

  • New Members
  • 195 posts

Posted 17 May 2012 - 12:07 PM

Also I was making it more complex then I needed it to be.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users