Author Topic: Arrays -- What are Arrays ??? a nobama speacil  (Read 14916 times)

0 Members and 1 Guest are viewing this topic.

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Arrays -- What are Arrays ??? a nobama speacil
« on: October 14, 2010, 06:02:27 AM »
+1
Arrays arrays array.. in order to use LUA your going to have to understand arrays.  The good news is everyone already knows what an array is they just dont know it.
Imagine a shopping list of things to buy such as
milk
eggs
bacon

Believe it or not but thats a bloody array. Its an array with 3 items (or Elements). Lets call our list/array ShoppingList... now whats the 2nd element/item  eggs .. or shoppinglist[2]

What that carnt be an array .. thats 2 dam easy. Lets turn that into lua  first we create our shopping list emtpy then add elements, then lets print the second item
Code: [Select]
shoppinglist = {}
shoppinglist[1] = 'milk'
shoppinglist[2] = 'eggs'
shoppinglist[3] = 'bacon'

print('2nd item: '..shoppinglist[2])

This can also written in lua be done in a simplular way... Note the  {} start and end of an array definition
Code: [Select]
shoppinglist = { 'Milk' , 'eggs', 'bacon'}
print('2nd item: '..shoppinglist[2])


_____________________________________________________________________
Now lets all be clever clogs... the word Bacon is an array ???!!!!!  You what you say... well it is .. tell me the 3rd letter of the word bacon....  3rd umm letter or did you mean element... well its c either way.  In lua to get an element of a string (array of characters) you have to use a speacil command.
Code: [Select]
print('3rd element of bacon: '..string.sub(shoppinglist[3], 3,3))

_____________________________________________________________________
Ok interesting... but what is a Table.. a table is an array of arrays... ow jimmy now where going crazy.. but wait you already know what an array of arrays is... its your dam schedule...

Monday
   mow lawn
   take out garbage
tue
  pay the bills ow lord
  start on fixing the roof
wed
  drink beer

In Lua
Code: [Select]
MySchedule = {}    -- make an empty table/array
MySchedule[1] = { 'Monday' , 'mow lawn', 'take out garbage' }
MySchedule[2] = { 'tue' ,'pay the bills ow lord',' start on fixing the roof' }
MySchedule[3] = { 'wed','drink beer' }

You could also represent this as
Quote
MySchedule = { { 'Monday' , 'mow lawn', 'take out garbage' } , { 'tue' ,'pay the bills ow lord',' start on fixing the roof' } , { 'wed','drink beer' } }

Now tell me the second thing to do on tue and the 1st thing to do on the third day
Code: [Select]
print('Whats the 2nd item to do on TUe: '..MySchedule[2][3]) -- note 2nd thing is 3rd element in array
print('Whats the 1st item to do on the third day: '..MySchedule[3][2])


_____________________________________________________________________

Now thats arrays/list and tables  (arrays or arrays/lists of lists)  Simplified maybe but the gist of it..
Now to apply to some serious code....

scanitems(visible)   makes a array of Variables of all items found
each element of the array .. contains an list of varialbes that apply to that item found (id id,name, position)
to get each element of the talbe we use UO.getitem(INDEX/element number) and it returns all the values...

Code: [Select]
itemsfoundcount = UO.ScanItems(true) -- visible
local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(5)
print('The fifth item found ID is: ..nID)
 

_____________________________________________________________________
Please leave a comment to let me know if this was usfull or rocket science.
« Last Edit: October 14, 2010, 07:13:56 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Scrripty

  • Guest
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #1 on: October 14, 2010, 08:03:42 AM »
+1
I knew what an array was already, but the lua syntax was still a mystery.  Very helpfull. :)

Offline NObama

  • Everything I need to know, I learned from Miffy's Item Finder.
  • Elite
  • *
  • *
  • Posts: 3454
  • Activity:
    0%
  • Reputation Power: 43
  • NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.
  • Respect: +325
  • Referrals: 2
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #2 on: October 14, 2010, 09:41:43 PM »
+1
Yay!  A NObama special!

(Maybe this time, I'll actually understand...)

Thanks, EN!

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #3 on: October 15, 2010, 10:01:27 AM »
+1
Yay!  A NObama special!

(Maybe this time, I'll actually understand...)

Thanks, EN!

LOL i wrote it for you as somewhere in some post you were bashings arrays and your inablity to be compatible with them logically. But arrays are essential for more complex lua stuff on just nice lua stuff.. just basic arrays.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +600
  • Referrals: 2
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #4 on: October 19, 2010, 07:55:04 AM »
+1
Another great explanation EN! +rep from me for these write-ups!

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #5 on: October 19, 2010, 09:07:11 AM »
+1
Another great explanation EN! +rep from me for these write-ups!
X

Did i miss it is something is the rep system working again.... and if so how do you +rep something .. or is this just a metaphorical +rep
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +600
  • Referrals: 2
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #6 on: October 19, 2010, 09:26:26 AM »
+1
<----- Click on the heart underneath the posters name
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #7 on: October 19, 2010, 09:34:15 AM »
+1
<----- Click on the heart underneath the posters name

that explains why i missed it i dont see any hearts
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13312
  • Activity:
    0.4%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +3089
  • Referrals: 34
    • View Profile
    • ScriptUO
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #8 on: October 19, 2010, 09:37:03 AM »
+1

that explains why i missed it i dont see any hearts

You won't see any hearts under your own posts, else you'll be able to give rep to yourself.  That's been known to cause blindness and an acute case of hairy palms.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #9 on: October 19, 2010, 09:47:19 AM »
+1

that explains why i missed it i dont see any hearts

You won't see any hearts under your own posts, else you'll be able to give rep to yourself.  That's been known to cause blindness and an acute case of hairy palms.

I dont see hearts under any posts in any threads...   unless ive already got the blindness your speaking of I know ive got the hairy palms aready lol
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +272
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #10 on: October 19, 2010, 09:49:01 AM »
+1
Also, you can make a dynamic table


Code: [Select]
schedule = {
{ "mon", "work", "eat", "hw", "sleep"},
{ "tue", "work", "mow", "run", "Cook"},
{ "Wed", "Pay Bills", "Errands", "Sleep", "Play Video Games"}
}

and then call it with unpack command

Code: [Select]
for i = 1,#schedule
sDay, sFirst, sSecond, sThird, sFourth = unpack(schedule(i))
-- code for checking/doing things here
end
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13312
  • Activity:
    0.4%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +3089
  • Referrals: 34
    • View Profile
    • ScriptUO
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #11 on: October 19, 2010, 11:20:12 AM »
+1
Be careful with the use of "{}", "[]" and "()".  They address identifiers in specific ways.  Since you are referencing a table, you're code should look like this:

Code: [Select]
schedule = {
{ "mon", "work", "eat", "hw", "sleep"},
{ "tue", "work", "mow", "run", "Cook"},
{ "Wed", "Pay Bills", "Errands", "Sleep", "Play Video Games"}
}

for i = 1,#schedule do -- added "do"
sDay, sFirst, sSecond, sThird, sFourth = unpack(schedule[i])  -- changed (i) to [i]
-- code for checking/doing things here
end
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Endless NightTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #12 on: October 19, 2010, 11:34:57 AM »
+1

that explains why i missed it i dont see any hearts

You won't see any hearts under your own posts, else you'll be able to give rep to yourself.  That's been known to cause blindness and an acute case of hairy palms.

I dont see hearts under any posts in any threads...   unless ive already got the blindness your speaking of I know ive got the hairy palms aready lol


My sight has been restored I now see hearts.. thank goodness .. now what to do about these hariy palms umm
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +272
  • Referrals: 1
    • View Profile
Re: Arrays -- What are Arrays ??? a nobama speacil
« Reply #13 on: October 19, 2010, 03:21:50 PM »
+1
Ah yes, my bad tm. I see that now in my own script

local sSkill, nMaxLevel, nMinLevel, nSpell, bTarget, nDelay, nMana = unpack(spells)
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Tags: