Jump to content




type( {} ) ~= "table"


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

#1 YoYoYonnY

  • Members
  • 49 posts

Posted 26 April 2014 - 07:49 PM

local function redraw()
  renderOrder = {}
  assert( type( renderOrder ) ~= "table", "renderOrder's type is not table" )
end
redraw()
What am I missing? Is it a bug in ComputerCraft or a bug in my program? Please help?!?
When I use renderOrder[ 1 ] == {} it errors aswell.

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 26 April 2014 - 07:58 PM

This is how assert works: it takes a first parameter as a condition (condition can be anything) and checks wether it is false or nil. If it is then it errors using the message that was set as the second parameter. If the condition was not equal to false or nil then it returns all parameters passed to assert function.

Note: '~=' in Lua means 'not equal'.

I hope that will help you to find your problem :).

#3 YoYoYonnY

  • Members
  • 49 posts

Posted 26 April 2014 - 08:58 PM

View PostMKlegoman357, on 26 April 2014 - 07:58 PM, said:

This is how assert works: it takes a first parameter as a condition (condition can be anything) and checks wether it is false or nil. If it is then it errors using the message that was set as the second parameter. If the condition was not equal to false or nil then it returns all parameters passed to assert function.

Note: '~=' in Lua means 'not equal'.

I hope that will help you to find your problem :).
Thanks, I used ~= when debugging after using == when testing, I guess. At least, when I rebooted, everything else worked fine ( renderOrder[1] = {} didnt work before the reboot, it gave type( renderOrder[1] ) == "nil" )

#4 HometownPotato

  • Members
  • 62 posts

Posted 26 April 2014 - 09:06 PM

YoYoYonny, Your first should of worked correctly.
Assuming you are checking not equal to "table"

Edited by HometownPotato, 26 April 2014 - 09:06 PM.


#5 YoYoYonnY

  • Members
  • 49 posts

Posted 27 April 2014 - 12:08 AM

View PostHometownPotato, on 26 April 2014 - 09:06 PM, said:

- Snip -
The first problem was I used ~= instead of ==.
The second problem was I used local renderOrder and global renderOrder.
When I tried == with a global renderOrder everything worked fine.
But when I tried ~= with a local renderOrder it would error (It couldn't find renderOrder as a table), and I didn't know how (Its always wierd when you get an unexpected error while debugging).

#6 HometownPotato

  • Members
  • 62 posts

Posted 27 April 2014 - 02:12 AM

Oh I just realized that. I'm blind





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users