I suck at tables.

Post Reply
User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

I suck at tables.

Post by Alexander Divine »

I'm trying to get my stinkin' list of afflictions to do anything, at all. I'm sure something is wrong with the basic way I set it up, and if I can figure it out I'll be good to go.

The following incredibly long spammage is my Affliction Handling script, or at least the very beginning of it. Right now I'm just making a table of afflictions with their respective on/off values. My problem is that I can't seem to do anything with them. If I do echo(v) it shows me a long string of zeros that seem to correspond with how many items are in the list, but I cannot for the life of me get it to do echo(k). All references to a specific affliction don't work. I even tried a simple test alias to do afflictionList.fear = 1 and then echo(afflictionList.fear), but nothing works at all. Any insight would be most appreciated.

Code: Select all

afflictionList = {
  ["addiction"] = 0,
  ["aeon"] = 0,
  ["agoraphobia"] = 0,
  ["anorexia"] = 0,
  ["asthma"] = 0,
  ["baldness"] = 0,
  ["berserking"] = 0,
  ["black_bile"] = 0,
  ["blood_curse"] = 0,
  ["blood_effusion"] = 0,
  ["blood_poisoning"] = 0,
  ["blurry_vision"] = 0,
  ["body_odor"] = 0,
  ["burning"] = 0,
  ["claustrophobia"] = 0,
  ["clumsiness"] = 0,
  ["confusion"] = 0,
  ["deadening"] = 0,
  ["dementia"] = 0,
  ["disfigurement"] = 0,
  ["disrupt"] = 0,
  ["dissonance"] = 0,
  ["dizziness"] = 0,
  ["earth_rot"] = 0,
  ["epilepsy"] = 0,
  ["fear_of_commitment"] = 0,
  ["frozen"] = 0,
  ["generosity"] = 0,
  ["haemophilia"] = 0,
  ["hallucinations"] = 0,
  ["hatred"] = 0,
  ["heartflutter"] = 0,
  ["hellsight"] = 0,
  ["hypersomnia"] = 0,
  ["hypochondria"] = 0,
  ["idiocy"] = 0,
  ["impatience"] = 0,
  ["indifference"] = 0,
  ["justice"] = 0,
  ["lethargy"] = 0,
  ["limp_veins"] = 0,
  ["loneliness"] = 0,
  ["lovers_effect"] = 0,
  ["masochism"] = 0,
  ["pride"] = 0,
  ["pacifism"] = 0,
  ["paralysis"] = 0,
  ["paranoia"] = 0,
  ["peace"] = 0,
  ["phlegm"] = 0,
  ["plodding"] = 0,
  ["recklessness"] = 0,
  ["sadness"] = 0,
  ["self_pity"] = 0,
  ["selarnia"] = 0,
  ["sensitivity"] = 0,
  ["shivering"] = 0,
  ["shyness"] = 0,
  ["slickness"] = 0,
  ["spinal_rip"] = 0,
  ["stupidity"] = 0,
  ["stuttering"] = 0,
  ["sunlight_allergy"] = 0,
  ["thin_blood"] = 0,
  ["throat_slash"] = 0,
  ["vertigo"] = 0,
  ["vomiting"] = 0,
  ["voyria"] = 0,
  ["weariness"] = 0,
  ["yellow_bile"] = 0,

  ["bound"] = 0,
  ["entanglement"] = 0,
  ["feed"] = 0,
  ["hanged_man"] = 0,
  ["hoist"] = 0,
  ["impaled"] = 0,
  ["lure"] = 0,
  ["quicksand"] = 0,
  ["transfix"] = 0,
  ["web"] = 0,

  ["broken_left_arm"] = 0,
  ["broken_right_arm"] = 0,
  ["broken_left_leg"] = 0,
  ["broken_right_leg"] = 0,
  ["broken_head"] = 0,
  ["broken_torso"] = 0,

  ["jawlock_armpit"] = 0,
  ["jawlock_neck"] = 0,
  ["jawlock_thigh"] = 0,

  ["mangled_left_arm"] = 0,
  ["mangled_right_arm"] = 0,
  ["mangled_left_leg"] = 0,
  ["mangled_right_leg"] = 0,
  ["mangled_head"] = 0,
  ["mangled_torso"] = 0,

  ["blind"] = 0,
  ["deaf"] = 0,
  ["insomnia"] = 0,
  ["prone"] = 0,

  ["fear"] = 0
}

-- Just trying to make the stupid thing recognize my afflictions, when
-- that works we can actually have it reset the values
function resetAfflictions()
  for k,v in pairs(afflictionList) do
    print(k,v)
  end
end

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: I suck at tables.

Post by ixokai »

I -think- you just want:

Code: Select all

afflictionList = {
    "addiction" = 0,
    "..." = 0
}
You can make strings with double-square-brackets, but a single square bracket with a string inside, I have no idea what that would produce or if it produces anything at all.

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: I suck at tables.

Post by Alexander Divine »

Oh, weird. I must've misunderstood the table tutorial. Lemme try that and I'll see if it works.

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: I suck at tables.

Post by Alexander Divine »

I was getting an error when I removed the brackets. Just to make sure I didn't screw something up re-writing it, I even tried:

Code: Select all

plumberList = {
  "Mario" = 1
}
And that didn't work either. :(

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: I suck at tables.

Post by Heiko »

Code: Select all

myEnnemies = {  "Peter", "Jim", "Carl", "John" };

e2 = { k1="Peter", k2="Jimmy", k3="Johnny"};

display( myEnnemies );
display( e2 );

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: I suck at tables.

Post by ixokai »

Oh, so the key has to be an un-quoted string, unless you do it as ["blah"] which is what you did originally. With this in mind, I went back to your original code-- and it all worked perfectly.

As long as one used "echo" and not "print" :)

Code: Select all

for k,v in pairs(afflictionList) do
    echo(k..v)
end
So you don't suck at tables after all. :) Although personally, I find...

afflictionList = {
addiction = 0,
aeon = 0,
...
}

More readable then the ["stringified"] form, and since you're using all simple strings it shouldn't be problematic. Sorry for confusion in earlier reply. I'm not a lua expert :)

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: I suck at tables.

Post by Alexander Divine »

Actually, that was the problem, right there. I'm just really dumb.

Nevermind the "print" up there, I actually changed it to "echo." The problem was that I was doing echo(k,v) like in the table tutorial, when I completely forgot about k .. v.

Lulz, it works fantastic now. Thanks!

Post Reply