![]() |
Search array name
Is there a way to search and pull up all array names that would start with certain letters? Like there are the array Graalmember1, Graalmember2, Graalmember3, Cutfish, Bombs.
And I want to show the arrays that start with Graal in a gui? |
Not a built-in way, but it's easy to script
PHP Code:
|
I leave the array part as array correct? being that there are many different array names?
and can call that function like: searchArray(array, start); correct? bleh, to be more specific. searching through the arrays ingraal1, ingraal2, ingraal3, graal4, cuddlefish, bombs, arrows, penguins to pull up only the ones that have "ingraal" in the array name, then display the number after "ingraal". so it finds ingraal1, ingraal2, ingraal3, then displays 1 2 3 |
Hint: using .substring
|
Something like this I guess
PHP Code:
|
Can you explain that though please? and how to call it correctly? I also dont wannt just copy, i wanna understand
|
Quote:
PHP Code:
|
the problem is, that doesnt seem it will work. Im not trying to search for values in an array. Ill set it up more clear.
Array ingraal1 {hi,how,he} ingraal2 {k,m,c,b,d} ingraal3 {op,asd,g,a} cuddlefish {2,5,213,2,0} bombs {sjd,23,6,a} arrows {s,d,e,gf,a} Trying to search the NAME of the array, not the names inside the array. So i want to pull out the array names that have "ingraal" in them, which would pull ingraal1, ingraal2, ingraal3. Then, i was wanting to print out what is after "ingraal" so it would show up 1 2 3 from the "ingraal(1-3)" array names. |
I meant that .substring functions essentially as #e did in gscript in this case. You can use that to compare clusters of letters to entries found within your array and then extract desired information from the matches.
It is .substring(start,len) after all. :) |
That completely went over my head. Please explain in more simple words :)
|
if you have an array called this.arr, this.arr.name will return arr.
However, I can't see any useful implementation of what you're asking for since searching through the arrays to see what begins with "ingraal" requires you already knowing exactly where they are and searching each one manually. If you were to pass an array of arrays to the function and check through all the arrays in there, this.collectedarrays[0].name returns nothing. |
Ive been just using examples. What im actually doing is i have guilds register on a server to have and give rights to members for certain things.
when it creates the array it creates it as registeredguildsGUILDNAME={acct name, acct name} so i need to search through the array names that are registeredguilds then find the GUILDNAME, so i can print out the entire list of the GUILDNAMES that are registered on my server in a gui. any other ideas on how to go about that, please let me know. |
I'd recommend using TStaticVar's.
PHP Code:
|
can that be used with server.var?
rather not use this.var b/c if the level is updated every single guild has to reregister. |
use a database NPC
|
Been a while since i had a playerworld, it was right when npc servers came out, how you set up a db npc
|
Click the Green Dragon DB-NPC button, then click Add in the NPCs window that pops up, fill in the appropriate information in the next window that pops up and click Apply.
|
The level i add it on to start, is that the level it works on?
I dont want it to work everywhere. If not, of if i guess, how do i "call" it in a level npc? |
Quote:
findnpc(dbnpcname).function() or if you plan on calling the NPC a few times, store the npc in a var (cont = findnpc(dbnpcname) ) |
I read some stuff on graal.net, but still dont really understand this.
If i have this script in a db npc, how is the results going to show up on my gui in a level? actually worded better: how am i going to take this.vars from the db npc, and then pick out parts of the name, then show it up on a gui in a level npc. |
Quote:
Quote:
|
so i can go
PHP Code:
so i could do PHP Code:
|
Actually, doesnt seem to be working. heres my script:
PHP Code:
And i used this on a level npc: PHP Code:
|
Why are you still using clientside for chat commands?
|
I did take it out, thats actually a bit old, same script just minus //#CLIENTSIDE
|
simply finding the NPC on it's own in your script will not do anything.
You need to have a var point to it after returning it. Also, you cannot read this.vars from server to client like that. My suggestions are to move nearly everything out of the clientside, store the few things you want accessible by GUI into the DB NPC's attribute array, copy the attribute array to the level NPC (although a weapon would probably be better for guild GUI related things), then display on clientside. Example - PHP Code:
|
The thing is, player has to chat to set it. Do i include that in the npc db too? see my script and what its doing. thats why i used a serverr.flag, its less of a pain, but if TStaticVar() is the only way to do what i need to do, compared to the script i posed before that one, then i guess i have to.
I guess Im lost enough to ask someone to show me, at the least, a full example. :/ The thing is, if you read the code i posted, its not just gui. That entire code sets a register server.flag for each guild registered, so playerchats and everything is involved. On a seperate npc i was using a gui to list the guilds that were registered. Im lost, and just getting confused even more now. |
I worked with Cyril today, and got something working. He's currently working on interfacing with a GUI, so he might come up with some more questions. Here are the scripts, for future reference:
DB NPC (db_registeredguilds) PHP Code:
PHP Code:
|
Why are you using findNPC? There's no need to, you can simply reference it as an object.
|
Quote:
|
Quote:
|
Quote:
PHP Code:
|
I personally don't trust DB-NPCs enough to do that.
|
Quote:
|
Wouldn't findNPC() be less efficient because you're calling a function to get the object instead of just referencing it by name? Especially when people use findNPC(npcname) over and over again instead of assigning the npc to some variable.
I have no idea, but it just seems like it would be. |
Quote:
PHP Code:
NPC Code: Specifying findNPC every time appears to take twice as long (in my benchmark anyway) compared to variable and direct methods. |
Quote:
This: PHP Code:
PHP Code:
|
Quote:
Like I said in a post previously, what you are requesting assistance for seems dubious at best. I don't believe there is any way to collect all the server variables at once by function, and since there isn't, you would have to know the names of the variables before hand. That being the case, you aren't really yielding any benefit by doubly checking them to see if registeredguilds is a part of the name. I don't know how to explain this any better. If there is a way to return all the server flags at once, as was said, you could iterate through that array and check if the array at whatever index in the for loop's name starts with or contains whatever string (in this case, regsistered guilds). |
temp.servervars = getstringkeys("server.");
may work. |
Quote:
PHP Code:
PHP Code:
|
| All times are GMT +2. The time now is 02:41 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.