Author Topic: ID of List Option  (Read 1091 times)

"list Apple 0 Bird 1 Cat 2"
When someone selects "Apple" by clicking it, the value 0 is used.

---

Is there a way to get the ID in the list of "Apple"?
Such as a function that would return "0" with input of "Apple".

Just, it doesn't know that Apple = 0 from the start.
That way it'll work with any list option, etc.

So you are trying to find out somones id?

Not at all.
If you don't know what you're talking about, please don't post.


Could you use an array?

list[0] = apple;
list[1] = bird;

Then use a for() loop to check for the IDs


I believe there's a better way of doing this but I don't know what it is

Well the thing is I won't always know whats on the list.
When the user inputs a string and a list, it'll search the list and return the ID that corresponds with the string.

(Users can create their lists, so I won't know what to expect.)

So they'd input "cat dog fish"

And you'd make a function that turns it into

list[0] = "cat";
list[1] = "dog";
list[2] = "fish";

Your searching function would loop through the array using for(), checking for matches of "dog" or whatever

if (list[%i] $= "dog") return %i;

Something similar at least.


I expect Ephi to come along and point out how I'm horribly wrong :(

The lists are ones in output event parameters.
So... would I package registerOutputEvent and check for lists?
And if they have a list, make an array?

Code: [Select]
package CheckForLists
{
function registerOutputEvent(%target, %name, %parameters, %client)
{
Parent::registerOutputEvent(%target, %name, %parameters, %client);
for(%i=0;%i<getFieldCount(%parameters);%i++)
{
if(firstWord(getField(%parameters,%i)) $= "list")
{
// Create array
}
}
}
};
activatePackage(CheckForLists);

Does that look right?
EDIT: Forgot Parent::.
« Last Edit: November 27, 2008, 11:30:16 AM by Truce »

Well, to do this you would loop every word of the parameter after the first, check if it is a numerical value and store the words after it that are not numerical values.

I'd use an array like:
$Event_List[eventname,id]=returnvalue

Then as the function:
Code: [Select]
function getEvList(%eventname,%id)
{
return $Event_List[%eventname,%id];
}

An edited version of my checkHex function:
(uses a support function)
Code: [Select]
function isInCharList(%char,%list)
{
%cnt=getWordCount(%list);
for(%i=0;%i<%cnt;%i++)
{
if(%char$=getWord(%list,%i))
{
return 1;
}
}
return 0;
}

function checkNum(%str)
{
%cnt=strLen(%str);
for(%i=0;%i<%cnt;%i++)
{
%sub=getSubStr(%str,%i,1);
if(!isInCharList(%sub,"0 1 2 3 4 5 6 7 8 9"))
{
return 0;
}
}
return 1;
}

If you have no idea on how to use that:
Code: [Select]
checkNum("123") returns 1
checkNum("wat") returns 0
checkNum("w4t") returns 0

I guess you can figure out the rest now...?

Is there a way to get the ID in the list of "Apple"?
My brother's name used to be apple :D
« Last Edit: November 27, 2008, 02:33:58 PM by Robo Noob »

Code: [Select]
switch(%input)
{
 case 0:
  //do stuff for 'Apple'
 case 1:
  //do stuff for 'Bird'
 case 2:
  //do stuff for 'Cat'
}

There's probably something you can do with the list of server output parameters (dump/export global variables) if you really want to extract the information like that, but a switch statement is usually easier.

whateverYourListObjectNameIs. dump();
Look at all the get______ stuff, that should help a lot.