Jump to content




How Would I Map A Screen



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

#1 jay5476

  • Members
  • 289 posts

Posted 26 August 2013 - 03:20 AM

eg. i want to have a table with all positions and set them to either true or false, false by defualt
and then call them later like
x = 1
y = 1
if screen[y][x] then
-- stuff
end
and it would return true if on column x on line y was true

#2 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 26 August 2013 - 03:25 AM

So you want to have all the content on the screen in a table?
Overwrite the existing functions and store everything.

#3 jay5476

  • Members
  • 289 posts

Posted 26 August 2013 - 05:37 AM

Yes I know but how would I do this not overly great with tables somehow

#4 McLeopold

  • Members
  • 123 posts

Posted 26 August 2013 - 08:33 PM

Tables are the only way to do this. Lua doesn't have arrays, just indexed hashes. Initialize a table like this:

local screen = {}
for r = 1, rows do
  screen[r] = {}
  for c = 1, cols do
	screen[r][c] = false
  end
end


Then you can set a value like this:

screen[c][r] = true

You could try and use strings instead of tables, but then you'll have a bunch of code like screen:sub(3,3) == "t" to get a value and setting a value would require rebuilding the string. It would be slower, so stick with tables.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 August 2013 - 09:30 PM

View Postjay5476, on 26 August 2013 - 05:37 AM, said:

Yes I know but how would I do this not overly great with tables somehow
One of the best resources you could ever read.

#6 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 26 August 2013 - 09:32 PM

"Lua doesn't have arrays, just indexed hashes"
Wut :x


i usually use strings for these types of things

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 August 2013 - 09:54 PM

View PostPixelToast, on 26 August 2013 - 09:32 PM, said:

"Lua doesn't have arrays, just indexed hashes"
Wut :x
Yeah I was pretty confused by that too.

#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 27 August 2013 - 07:13 AM

in my sig is a link to my utils post, in my utils post is a layer API that does this and more. Just remove the local property of the record table and go. it records lines as strings though so use record.text[y]:sub(x,x) to get the info back or just the getTextAt function

#9 McLeopold

  • Members
  • 123 posts

Posted 27 August 2013 - 09:56 AM

View Posttheoriginalbit, on 26 August 2013 - 09:54 PM, said:

View PostPixelToast, on 26 August 2013 - 09:32 PM, said:

"Lua doesn't have arrays, just indexed hashes"
Wut :x
Yeah I was pretty confused by that too.

Lua only has 8 basic data types. The only two that can be used like an array are a string and a table. A table is not truly an array in the sense that the memory is a contiguous block of data that provides you random access. It is a data structure that uses a lookup table and linked lists of values, which means you are hashing keys and using a collision strategy to find your values. A string is a contiguous block of data, but it is immutable. You can easily get a value from the middle of a string, but you can't easily set it. If you want to replace a character in the middle, you are creating an entirely new string, not just modifying one byte in the middle.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users