Hi i want to do simple table with room positions in it
How can I look for previous RoomID?
t = {1212, 1111, 4444, 5555}
last RoomID was 5555 so how to extract 4444 ?
And if table look like:
t = {2222, 5555, 4444, 5555}
there won't be bug like lastRoomID will matches as 2222 (should be 4444) because script matches first 5555 in table?
And second question: I have 2 tables with i want connect to table "enemies" but what i have tried it displays an empty table
elves = {
{desc = "high elf", name ="bob"},
{desc = "wood elf", name ="Tree"},
}
ogres= {
{desc = "pink ogre", name ="pinky"},
{desc = "blue ogre", name ="brain"},
}
And last question how to make alias for searching tables
/find pinky
desc = "pink ogre", name ="pinky", guild = "ogres"
Table problems
-
- Posts: 97
- Joined: Wed Jul 25, 2012 12:35 pm
Table problems
English is not my native language. If you don't understand what im writing ask.
Ubuntu 17.04, Mudlet 3.1
Ubuntu 17.04, Mudlet 3.1
Re: Table problems
Didn't quite understand some of that, but hopefully this will help:
So say you want an alias to list every ogre name, you could:
azure_glass wrote: How can I look for previous RoomID?
You can do something like this for your table:azure_glass wrote: I have 2 tables with i want connect to table "enemies" but what i have tried it displays an empty table
With the table above, values are stored like so: elves[1].desc which would return "high elf"
So say you want an alias to list every ogre name, you could:
Hope that helps!
-
- Posts: 97
- Joined: Wed Jul 25, 2012 12:35 pm
Re: Table problems
Thanks for response.
I need to improve my English writhing skill...
About searching previous roomID i mean:
Long table with i don't know how big is.
And every visited room adds another value.
The problem is in that i want to search previous value to last added value
Another question if table contains x > 1000000 values
that affect on speed of script?
Do i have to clear this table?
I need to improve my English writhing skill...
About searching previous roomID i mean:
Long table with i don't know how big is.
And every visited room adds another value.
The problem is in that i want to search previous value to last added value
Another question if table contains x > 1000000 values
that affect on speed of script?
Do i have to clear this table?
English is not my native language. If you don't understand what im writing ask.
Ubuntu 17.04, Mudlet 3.1
Ubuntu 17.04, Mudlet 3.1
Re: Table problems
In order to see the last element of a table, you would index into it like so:
This, of course, only works with numerically indexed tables. Key-value tables have no order, and so you cannot find the last element.
As for searching, this is a complex topic, and is often implementation specific, as it is in your case. I can provide an implementation, though this is a simplistic solution.
First, your alias:
Therefore, you can easily see that in order to get the second-to-last value, you should do this:
The # symbol gets you the length of a table. Because Lua tables begin with index 1 (as opposed to 0), the last element in the table is at the index equal to the length of the table.
This, of course, only works with numerically indexed tables. Key-value tables have no order, and so you cannot find the last element.
As for searching, this is a complex topic, and is often implementation specific, as it is in your case. I can provide an implementation, though this is a simplistic solution.
First, your alias:
And now, your code:
As always, this comes with a disclaimer: this code was not tested. I typed it into the forums directly. If it doesn't work, check the error window and try to fix it yourself first. This may not solve your problem, given it was written based on the limited information provided. However, this should easily serve as a starting point.
Re: Table problems
Nice reply, though if I may add, # can also be used to determine the length of other types, most notably strings. It's really handy.
-
- Posts: 97
- Joined: Wed Jul 25, 2012 12:35 pm
Re: Table problems
Thanks for your replies
I have found some code on forum and i have something like this for sorting my guild chest;
It's causing huge lags and "|" is not coretly positioned if item has longer/shorter name.
How to improve it?
- no lags
- adding replace like: "two" swords to "[ 2]" swords
- and propper columns.
- sometimes color sword if magic
Text for testing:
I have found some code on forum and i have something like this for sorting my guild chest;
Code: Select all
tab = matches[5]
tab = string.split(tab, ",")
--display(t)
deleteLine()
echo("\n")
local inc = math.ceil(#tab*0.5)
for i = 1,inc do
local val1 = tab[i];
local val2 = tab[i + inc];
if( not val1 ) then val1 = ""; end;
if( not val2 ) then val2 = ""; end;
print(" |", val1.." \t| ", val2.." |");
end
display(#tab)
How to improve it?
- no lags
- adding replace like: "two" swords to "[ 2]" swords
- and propper columns.
- sometimes color sword if magic
Text for testing:
Code: Select all
Open wooden chest contains cztery nabijane czernione morgensterny, kosciana jednoreczna maczuge, masywna kolczasta wekiere, cztery drewniane duze maczugi, piec lekkich dlugich morgensternow, ciezka wymalowana zbroje plytowa, dwie polowe stalowe zbroje plytowe, siedem czarnych plomienistych sztyletow, solidny obreczowy helm, szesc czarnych luskowych kaftanow z okuciami, trzy tileanskie sprezynowe stiletta, cztery dlugie krwiste sztylety, dwa czernione kunsztowne napiersniki, wyprofilowany mocny napiersnik, czarny lsniacy helm, wiele posrebrzanych zdobionych sztyletow, polkulisty czarny helm z kita, szmaragdowosrebrna luskowa pare rekawic, szesc ciemnoszarych mocnych naramiennikow, dwa wytrzymale zdobione bigwanty, cztery mocne spizowe kirysy, piec dlugich szablastych naginat, kawaleryjski lyrijski nadziak, trzy zlociste luskowe karaceny, ciezka luskowa karacene, trzy poltorareczne zdobione miecze, smukly srebrzysty miecz, czarny obsydianowy miecz, szesc posrebrzanych szerokich katzbalgerow, szeroka ogromna partyzane, siedem masywnych brunirowanych nareczakow, brazowa wzmocniona pare butow, stalowa ciezka pare nareczakow, trzy lekkie stalowe pary naramiennikow, srebrzyste stalowe naramienniki, trzy kolczaste stalowe pary naramiennikow, czarna pare naramiennikow, dwa karbowane prawe naramienniki, srebrzysty lewy naramiennik, hematytowy smukly prawy naramiennik, lazurowy smukly lewy naramiennik, ciezki czarny lewy naramiennik, dwa srebrzyste prawe naramienniki, karbowany lewy naramiennik, drewniana okuta tarcze, okragla zdobiona tarcze, prostokatna metalowa tarcze, migdalowata solidna tarcze, drewniana poreczna tarcze, dwa ciezkie spizowe puklerze, dwa duze opancerzone fragmenty szkieletu, ciemny rawerowany kirys, szkarlatny lekki kirys, czarny duzy morion, spizowy solidny basinet, polyskliwy czarny helm, cztery mocne spizowe helmy, trzy czarne rogate helmy, stalowy wysoki basinet, dwa stalowe spiczaste szyszaki, czubiasty zdobny helm, dwa czarne luskowe helmy, dwie zdobione azurowe partyzany, pierscieniowy twardy kaftan, lazurowy wytrzymaly kaftan, blyszczaca zbroje plytowa, srebrzysta kolcza pare rekawic, szesc kolczastych plytowych par rekawic, pare wytrzymalych skorzanych rekawic, siedem skorzanych lsniacych par rekawic, lekki zdobiony polpancerz, dziewiec czarnych skorzanych kaftanow, antracytowa ornamentowana pare nareczakow, szara chropowata karacene, stalowa pare nareczakow, grube skorzane rekawice, plytowa dluga pare rekawic, dwie srebrzyste krotkie wekiery, szesc bojowych okutych cepow, zmurszala trojdzielna korseke, dwa dlugie bojowe nadziaki, dwa bursztynowe plomieniste sztylety, dwa zakrzywione krotkie nozyki, plomienisty lsniacy flamberg, dwa srebrzyste polyskliwe miecze, polyskliwy zakrzywiony scimitar, smukly trojkatny miecz, ciezka dluga glewie, dluga prosta gizarme, dziewiec srebrnych lsniacych toporow, czarna zdobiona halabarde, dluga czarna halabarde, polyskliwa bojowa halabarde, szmaragdowa ostra spise, dwa zielonkawe bretonskie mloty, ciezki zdobiony topor, waska trojdzielna spise, szesc ciezkich jednorecznych toporow, wysluzona dluga pike, polyskliwy runiczny mlot bojowy, olbrzymi spizowy mlot bojowy, krotki masywny mlot, trzy ornamentowane bojowe mloty, dwureczny gnomi mlot, dwureczny czarny mlot, trzy metalowe krotkie nadziaki, siedem krotkich lekkich nadziakow, dwa masywne bitewne mloty, dwa poreczne mahakamskie mloty wojenne, dwa zdobione srebrzyste obuszki, dwa srebrzyste jednoreczne topory, dwa poreczne polkoliste topory bojowe i dwie czarne rekawiczki.
English is not my native language. If you don't understand what im writing ask.
Ubuntu 17.04, Mudlet 3.1
Ubuntu 17.04, Mudlet 3.1