Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 9 10 11 12 13 … 18 Next »
Non exists entry returns true
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Non exists entry returns true
12-06-2016, 08:56 PM,
#1
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
Non exists entry returns true
Non exists entry return true on client side.

t[1]=true

after that I removed the entry and few seconds later I wanted to know if the record exists and it return true which is kinda weird since the table size prints as zero.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
12-06-2016, 08:59 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Non exists entry returns true
Going to need to have more information than just t[1]=true.
Find
Reply
12-06-2016, 09:02 PM, (This post was last modified: 12-06-2016, 09:03 PM by LocInt.)
#3
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Non exists entry returns true
This is how I perform the check.

i="Users"
window = {}
window.activeWindows = {}

Code:
if(not window.activeWindows[i]) then table.insert(window.activeWindows, i) window.activeWindows[i]=true end

This is how i removed the entry
Code:
local function removeEntry(t,entry) if(entry~=nil and #t>0) then for i=1, #t do if(t[i] == entry) then print(t[i]) table.remove(t,i) end end end end

After that I performed the first check again and it returned true even when the size was zero.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
12-06-2016, 09:07 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Non exists entry returns true
In your loop:
for i=1, #t do
if(t[i] == entry) then
print(t[i])
table.remove(t,i)
end
end
The variable i is shadowing the value you defined above. When you use table.remove, it removes the value at the index i, which is a number due to the loop. This does not remove the value you stored under window.activeWindows[ "Users" ], hence you get true.

Also, table length through #Table measures the size of the array part of a table. That is, it counts the number of values in a sequence starting at index 1. Thus, non-array indices (such as strings) do not get counted.

You need to do:
t[ entry ] = nil
table.remove( t, i )
to remove both the value in the array part, and the string indexed value.
Find
Reply
12-06-2016, 09:12 PM,
#5
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Non exists entry returns true
I tried to set the val as nil before i removed the entry but its still true.

Code:
t[i]=nil

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
12-06-2016, 09:13 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Non exists entry returns true
Read my answer again. In your remover function, i is coming from the loop, not your i = "Users" declaration above.
Find
Reply
12-06-2016, 09:14 PM, (This post was last modified: 12-06-2016, 09:15 PM by LocInt.)
#7
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Non exists entry returns true
(12-06-2016, 09:13 PM)Person8880 Wrote: Read my answer again. In your remover function, i is coming from the loop, not your i = "Users" declaration above.

Nvm my bad.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
12-06-2016, 09:22 PM,
#8
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Non exists entry returns true
Tables are intentionally a multi-purpose data store. All the table.* functions are just helpers for treating tables as arrays. Same with the length operator.

Anything that is not to do with an array structure is just standard assignment/indexing. This leaves tables as being able to represent pretty much any data structure, which in the end is a good thing. Just have to watch for the difference between the array part, and the "dictionary" part.
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.