Jump to content




Deleting Portions of Tables?


10 replies to this topic

#1 Pyrif

  • Members
  • 34 posts
  • Locationin a chair in my room, probably

Posted 12 June 2015 - 11:46 PM

I'm making a program that uses a table as text management. What I want to know how to do is "If any text reaches this portion of the table, delete that portion of the table and recreate it." Can anyone help me on this?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 June 2015 - 02:09 AM

Delete what when, and recreate how?

#3 Quintuple Agent

  • Members
  • 107 posts
  • LocationThis page

Posted 13 June 2015 - 02:32 AM

yah, we need some clarification on what you are asking.
Is you have text stored like so:
txtTab={
"this",
"is a test",
"On storing",
"Text"
}
So each index is a new line, or do you have some other way of storing it?
And what do you mean by reaches this portion of the table? If the text gets too long or if the table has so many lines?
Also, recreate it? make a new table, append it somewhere else?

#4 Pyrif

  • Members
  • 34 posts
  • Locationin a chair in my room, probably

Posted 13 June 2015 - 05:05 AM

Okay, I guess I should've explained better. :wacko:
So, what I have is a program that, when a timer event occurs, it shifts everything on the table right by one value (on a monitor). What I want to know is, if we let w=the width of the monitor, then how do we get rid of w+1 every step and restore it without moving w+1 to w+2?

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 June 2015 - 08:40 AM

You're still leaving out a lot of context. Why would you need to "get rid of" something that's off the screen, why would you want to "restore" it, and where would you even "restore" it to?

What are you actually trying to accomplish here? Are you making a scrolling text marquee, or attempting to make your map for Helios scroll, or... what? Where's the code you've got so far?

#6 Pyrif

  • Members
  • 34 posts
  • Locationin a chair in my room, probably

Posted 14 June 2015 - 03:46 AM

I was trying to make a decorative feature for a room I was making in my house, and I wanted to have everything on the screen shift to the right by one pixel, and get rid of the last horizontal pixel that wasn't on the screen. All of my colors are controlled by a table. Your closest guess was the scrolling text marquee. :3

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 June 2015 - 04:40 AM

Ok, so what's in the table, and how are you currently rendering its contents...?

#8 Square789

  • Members
  • 39 posts
  • LocationUniverse:C:/MilkyWay/Sol/Earth/Europe/Germany

Posted 14 June 2015 - 06:33 AM

The only thing i can do so far is giving you this link:
Table functions

#9 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 14 June 2015 - 10:18 AM

Is there a reason for the text that is already off-screen to be cut off? Monitors can deal with cutting text that doesn't fit by themselves, you can just write everything starting from a different position.

#10 Pyrif

  • Members
  • 34 posts
  • Locationin a chair in my room, probably

Posted 15 June 2015 - 12:48 AM

Each element in this table is another table containing colors (a 2D array). Every time a timer event happens, I want to shift each element to the right by one, put something new at the first column and get rid of the last column (which automatically recreates itself when I shift everything right by one).

#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 June 2015 - 01:10 AM

View PostLightMystic, on 15 June 2015 - 12:48 AM, said:

... and get rid of the last column (which automatically recreates itself when I shift everything right by one).

wut?

Anyway, it sounds like you just want to do this:

for y = 1, #theTable do                     -- For each entry (sub-table) in your main table, 
  table.insert(theTable[y], 1, <newValue>)  -- ... add an index to the front,
  table.remove(theTable[y])                 -- ... and remove the index from the end.
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users