ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Gemviper on January 28, 2017, 06:46:17 PM

Title: Placing misc words into an array
Post by: Gemviper on January 28, 2017, 06:46:17 PM
Lets say I have a half dozen words(or more) I'd like to place into an %array, how would I best do that?

Example: apple, monitor, computer, bike, kleenex and camera...\
set %array apple_monitor_computer_bike_kleenex_camera

That doesn't seem to work like it does for itemtypes, should it? After I perform an event property check I'd like to to run an if against the %array to find out if any of them are in there before I buy...

I know I can do individual checks such as if apple in #property || if...etc but that gets unwieldly if there are a couple dozen+ words in there. Suggestions?

edit: I am already running a loop on, for example, 125 items in a chest and during each item check I'd like to see if it has any of the words in it's property... without having an endless line of "if apple is in #property || monitor is in #property || etc."
Title: Re: Placing misc words into an array
Post by: TrailMyx on January 28, 2017, 09:56:55 PM
You could so something like this:

Code: [Select]
set %array0 apple
set %array1 monitor
set %array2 bike
set %array3 kleenex
set %array4 camera

for %i 0 4
{
  set %item %array . %i
  display ok %item
}

stop

Then you just reference each of the items with the index reference %array . %i

if you just want to use a string to build upon so you can use the "in" function, you can just do something like:

Code: [Select]
set %array0 apple
set %array1 monitor
set %array2 bike
set %array3 kleenex
set %array4 camera

set %string
for %i 0 4
{
  set %string %string , _ , %array . %i
}

display ok %string
stop
Title: Re: Placing misc words into an array
Post by: Gemviper on January 28, 2017, 10:10:29 PM
It might help if I'm more specific, I'm hoping it's possible to tighten up this particular sub a bit. It deals with 210 "words", each belonging to a different itemtype.

set %itemtypes AAA_BBB_CCC_DDD_EEE_ETC...
finditem %itemtypes etc

but instead of proceeding from there I need to confirm that a particular word is found in the #property of every %itemtypes found, which is itself in a loop that itterates through each result, among other things. Is it not possible to create a single, albeit long, "set" of words instead of creating a lot of arrays? I don't want to return a positive unless an %itemtypes and "word" combo is found. CHecking each result against a long list of arrays, or if statements, doesn't feel optimal for my specific needs with this.

Just to confirm, it's not possible to create a single "set" of many words and return a positive if any one word is in that set ?
Title: Re: Placing misc words into an array
Post by: TrailMyx on January 28, 2017, 11:01:48 PM
It might help if I'm more specific, I'm hoping it's possible to tighten up this particular sub a bit. It deals with 210 "words", each belonging to a different itemtype.

set %itemtypes AAA_BBB_CCC_DDD_EEE_ETC...
finditem %itemtypes etc

but instead of proceeding from there I need to confirm that a particular word is found in the #property of every %itemtypes found, which is itself in a loop that itterates through each result, among other things. Is it not possible to create a single, albeit long, "set" of words instead of creating a lot of arrays? I don't want to return a positive unless an %itemtypes and "word" combo is found. CHecking each result against a long list of arrays, or if statements, doesn't feel optimal for my specific needs with this.

Just to confirm, it's not possible to create a single "set" of many words and return a positive if any one word is in that set ?

Sure, that's actually easy (assuming I understand your question)

Given your example:

Code: [Select]
set %array _apple_monitor_computer_bike_kleenex_camera_

EasyUO has the two operators "in" and "notin"  so you can do something like this:

Code: [Select]
set %array _apple_monitor_computer_bike_kleenex_camera_
set %test1 _raptor_
set %test2 _computer_

if %test1 notin %array ; notice the usage of "notin"
{
  display %test1 is not in %array
}

if %test2 in %array ; notice the usage of "in"
{
  display ok %test2 is in %array
}

stop
Title: Re: Placing misc words into an array
Post by: BobOzarius on January 29, 2017, 01:16:25 AM
If you've already broken apart the #property into sections, you can name your variables what you're searching for, and set them to #true. Like if you're looking for very specific things.

Code: [Select]
set %arrayMonitor #true
set %arrayBike #true
set %arrayKleenex #true
set %arrayCamera #true

Then when you break apart your #property string, or you could even use the whole #property, and you get your result from each part, you can do some code like this:

Code: [Select]
for %I 1 %numberOfStringChunks
{
  gosub breakStringApartRight
  set %stringChunk n/a
  if %array . #result = #true
    set %stringChunk #result
  if %stringChunk = n/a
    display The variable is not in the #property.
  if %stringChunk <> n/a
    display The variable is in the #property.
}

Then you can use the %stringChunk variable if it's found to be in the #property in any way you like, in a variable to find what you are looking for in #property, or perform an action based on that item because it's the #result from earlier in the script, and it's in the #property.
Title: Re: Placing misc words into an array
Post by: NObama on January 29, 2017, 01:26:51 AM
Take a look at the BOD filterer I just posted.  It does exactly what you want.
Title: Re: Placing misc words into an array
Post by: Gemviper on January 29, 2017, 09:12:53 AM
Thanks guys
Title: Re: Placing misc words into an array
Post by: Gemviper on January 29, 2017, 05:05:57 PM
One last question,

set %group200 AAA_BBB
set %group450 CCC_DDD

During the sub calculations are made against itemtypes and a final value number is generated(ie: 200). The next section of the script requires that I check to make sure that the itemtype is indeed in the group bearing the final value number(ie: if the final value is 200 then that item's itemtype is in %group200).

Sounds simple, and I'm sure it is, but I'm drawing a brain fart on the syntax. Example:

set %finalvalue 200
IF #FINDTYPE in %group200

I don't want to repeat the above check for each of the 210 groups and obviously "IF #FINDTYPE in %group%finalvalue" won't work(example to give you an idea of what I'm after)... so how can I I append the %finalvalue number to the %group to come up with %group200 ?

Title: Re: Placing misc words into an array
Post by: TrailMyx on January 29, 2017, 05:13:57 PM
I you're just looking to append whatever is in %group to %group_200, this is probably what you're looking for:

Code: [Select]
set %group_200 %group_200 , _ , %group
Title: Re: Placing misc words into an array
Post by: Gemviper on January 29, 2017, 05:15:53 PM
I am... sorta. 1 of the values I will not know in advance however. A simplified example...

Code: [Select]
set %group200 KWI_AAA_BBB_ETC

finditem KWI C_ ;example
event property #findid
set %nametotal 200 ;ommited the math that came up with value for simplicity sake
IF #FINDTYPE in %group%nametotal ; <---- brainfart here, I don't want to add anything to the group, only check against %group200
display ok %nametotal is accurate

I know the item type values in %group200 but will not know the %nametotal in advance and I want it to check on the group that corresponds with the %nametotal only. Hope that makes sense
Title: Re: Placing misc words into an array
Post by: TrailMyx on January 29, 2017, 06:42:45 PM
Oh, are you trying to build the variable "%group200"?

If so, this bit of test code might help:

Code: [Select]
set %group200 test
set %nametotal 200
set %val % . group . %nametotal
display ok %val

stop

Run that and see if it does what you want.
Title: Re: Placing misc words into an array
Post by: Gemviper on January 29, 2017, 06:53:14 PM
Bingo. With php you can print the literal of any variable within the code itself, my brain was stuck trying to do the same here, lol.

Thanks TM.
Title: Re: Placing misc words into an array
Post by: TrailMyx on January 29, 2017, 06:58:13 PM
Yeh, EUO operator precedence rules are a bit wonky.  In all honesty, when I have to use the "," and "." operators, I generally write a bit of sample code to be sure they are executing in the correct order.
Title: Re: Placing misc words into an array
Post by: Gemviper on January 29, 2017, 06:59:49 PM
edit: my bad, it works... I had another brain fart. Time for bed I think.

Thanks TM
Title: Re: Placing misc words into an array
Post by: NObama on February 05, 2017, 03:32:19 AM
What is it that you're doing, Gemviper?
Title: Re: Placing misc words into an array
Post by: Gemviper on February 07, 2017, 11:58:06 PM
Testing.

I'm driven to do it, to my website code, to my scripts.... can't help it. There is always a more efficient way, it just takes time to find it :)