Jump to content


CCJJSax

Member Since 15 Dec 2012
Offline Last Active Feb 19 2020 06:16 AM
-----

Topics I've Started

Can't figure out what is deleting my table

20 August 2019 - 04:07 AM

I have a shortened version of my code, but it does the same weirdness. I have table (t) that only has one item in it, which is an array. After I run it through highScore() it changes to 0 even though I only reference it as tab, then again through pTab. The goal of highScore() is to return an list of all items in t in order by score. Why is this happening?

local function highScore(tab, spot)
local pTab = tab
local scores = {}
local winner
while #pTab > 0 do
  winner = {key = 0, score = 0}
  for k,v in pairs(pTab) do
   -- print(v.score)
   if v.score > winner.score then
    winner = {key = k, score = v.score}
   end
  end
  scores[#scores+1] = pTab[winner.key]
  table.remove(pTab, winner.key)
end
return scores
end
t = {
  {
    player = "TEST",
    score = 0,
  },
}
print(#t) -- prints 1 as it should
h = highScore(t)
print(#t) -- prints 0 when it should still be 1

[Self Solved aka me being dumb]

17 August 2019 - 09:18 PM

When I redirected textutils.pagedPrint(text) to the monitor, the blinking cursor was below where I would have expected it. It's no longer at the end of the text. Why would that be?
also I'm using the CC: Tweaked branch from SquidDev, if it matters.

Spoiler

Edit: nope I'm just being dumb. I know why it's doing it. now to find how to delete the post.