Jump to content




Using a table to remember variables and get those variables by calling the number in the sequence of which they where created.


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

#1 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 31 October 2012 - 12:12 AM

This code doesn't seem to remember the variables like the title says, it only seems to remember the latest one not the older ones
THE APPLICATION CODE[VERY messy]
Spoiler


#2 Doyle3694

  • Members
  • 815 posts

Posted 31 October 2012 - 12:21 AM

please, indent your code

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 31 October 2012 - 12:43 AM

I'm not quite getting what your problem is. could you explain a little bit more :P/>

#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 31 October 2012 - 12:46 AM

Ehm, one thing I can make of this is that you're using the variable isx as a number, but declared it as a string ("1").

#5 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 31 October 2012 - 12:50 AM

View PostDoyle3694, on 31 October 2012 - 12:21 AM, said:

please, indent your code
I never understood indenting. It's a waste of time. I find it really hard to read indented code, too.
EDIT:
I just devoloped my own version of indenting. It's easy to read yet it really easy for me to do.

View PostsIdEkIcK_, on 31 October 2012 - 12:43 AM, said:

I'm not quite getting what your problem is. could you explain a little bit more :P/>
When I write more to my table in the code, it erases the old data in the table rather than adding to it.


View PostOrwell, on 31 October 2012 - 12:46 AM, said:

Ehm, one thing I can make of this is that you're using the variable isx as a number, but declared it as a string ("1").
LUA finds what kind of thingy a variable is automatically.

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 31 October 2012 - 12:56 AM

View PostHithere__, on 31 October 2012 - 12:50 AM, said:

View PostDoyle3694, on 31 October 2012 - 12:21 AM, said:

please, indent your code
I never understood indenting. It's a waste of time. I find it really hard to read indented code, too.

View PostsIdEkIcK_, on 31 October 2012 - 12:43 AM, said:

I'm not quite getting what your problem is. could you explain a little bit more :P/>
When I write more to my table in the code, it erases the old data in the table rather than adding to it.


View PostOrwell, on 31 October 2012 - 12:46 AM, said:

Ehm, one thing I can make of this is that you're using the variable isx as a number, but declared it as a string ("1").
LUA finds what kind of thingy a variable is automatically.

Indenting is valuable for seeing the scope of various blocks as well as the flow of the logic in the program. It also makes it significantly easier for most people to read the code.

When you write new data to a table at an index you've already written to, it will of course overwrite the old data at that index. This is normal behavior. If you're misusing the table, expect to get undesired results.

Lua treats table[1] and table["1"] as different indices, for good reason. If you index it as a string once and as a number another time, don't expect it to work.

You need to not be so snippy and know-it-all with those trying to help you, especially when they're right.

#7 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 31 October 2012 - 01:03 AM

View PostLyqyd, on 31 October 2012 - 12:56 AM, said:

View PostHithere__, on 31 October 2012 - 12:50 AM, said:

View PostDoyle3694, on 31 October 2012 - 12:21 AM, said:

please, indent your code
I never understood indenting. It's a waste of time. I find it really hard to read indented code, too.

View PostsIdEkIcK_, on 31 October 2012 - 12:43 AM, said:

I'm not quite getting what your problem is. could you explain a little bit more :P/>
When I write more to my table in the code, it erases the old data in the table rather than adding to it.


View PostOrwell, on 31 October 2012 - 12:46 AM, said:

Ehm, one thing I can make of this is that you're using the variable isx as a number, but declared it as a string ("1").
LUA finds what kind of thingy a variable is automatically.

Indenting is valuable for seeing the scope of various blocks as well as the flow of the logic in the program. It also makes it significantly easier for most people to read the code.

When you write new data to a table at an index you've already written to, it will of course overwrite the old data at that index. This is normal behavior. If you're misusing the table, expect to get undesired results.

Lua treats table[1] and table["1"] as different indices, for good reason. If you index it as a string once and as a number another time, don't expect it to work.

You need to not be so snippy and know-it-all with those trying to help you, especially when they're right.
Thanks
To the bold text
I get like this if it's either late at night and I've gotten crudloads of errors in a program or if it's just REALLY late at night

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 31 October 2012 - 01:14 AM

Early in the morning for me :P/>

#9 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 31 October 2012 - 02:09 AM

View PostLyqyd, on 31 October 2012 - 12:56 AM, said:

View PostHithere__, on 31 October 2012 - 12:50 AM, said:

View PostDoyle3694, on 31 October 2012 - 12:21 AM, said:

please, indent your code
I never understood indenting. It's a waste of time. I find it really hard to read indented code, too.

View PostsIdEkIcK_, on 31 October 2012 - 12:43 AM, said:

I'm not quite getting what your problem is. could you explain a little bit more :P/>
When I write more to my table in the code, it erases the old data in the table rather than adding to it.


View PostOrwell, on 31 October 2012 - 12:46 AM, said:

Ehm, one thing I can make of this is that you're using the variable isx as a number, but declared it as a string ("1").
LUA finds what kind of thingy a variable is automatically.

Indenting is valuable for seeing the scope of various blocks as well as the flow of the logic in the program. It also makes it significantly easier for most people to read the code.

When you write new data to a table at an index you've already written to, it will of course overwrite the old data at that index. This is normal behavior. If you're misusing the table, expect to get undesired results.

Lua treats table[1] and table["1"] as different indices, for good reason. If you index it as a string once and as a number another time, don't expect it to work.

You need to not be so snippy and know-it-all with those trying to help you, especially when they're right.
Thanks for try to help, but I tried it and it didn't work. Do I need to run another command or is this just not possible?

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 31 October 2012 - 02:13 AM

Hmm? What'd you try that didn't work? I'm not sure what you mean.

#11 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 31 October 2012 - 09:55 PM

I need something to keep track of the number of the table[the key] and add new stuff to the table WITHOUT erasing the old stuff.

#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 31 October 2012 - 10:34 PM

View PostHithere__, on 31 October 2012 - 09:55 PM, said:

I need something to keep track of the number of the table[the key] and add new stuff to the table WITHOUT erasing the old stuff.

table.insert(table,"text")
Doesn't delete what is already in the table.

#13 ChunLing

  • Members
  • 2,027 posts

Posted 31 October 2012 - 11:11 PM

You want a normal queue structure. Just keep expanding the table sequentially. Insert works, but is slower.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users