Page 1 of 2

Arrays, cleanup question.

Posted: Sun Mar 26, 2017 2:42 pm
by eustace11
I would like to thank everyone for the replies to my previous post found at viewtopic.php?f=204&t=13617. You have all been extremely helpful and kind, and I have followed your advice.

As I previously explained, BASIC was my first computer language, used on an Atari800xl. I've had to research things like string, int, bool, etc. The following question(s) has(have) to do with the use of arrays and variables to parse data and perform separate actions based on a true/false check.

Snippet A:
/declare x int local
/delay 1
/for x 1 to ${NetBots.Counts}
/consent ${NetBots.Client.Arg[${x}]}
/delay 1s
/next x
/return


Snippet B:
/varset Bot TRUE
/declare x int local
/for x 1 to ${NetBots.Counts}
/varset NBToon${x} ${NetBots.Client.Token[${x}, ]}
/echo ${NetBots[${NBToon${x}}].Name}
/next x
/return


Both of these are building arrays based on the Netbot plugin. Snippet A is intended to have everyone connected to Netbot consent to a rezz. Snippet B is intended to create an array so HP% can be monitored. But, there are some major differences between the creations of those arrays.

#1
My first question is whether or not it would be possible to modify those two snippets to then build an array based not on the NetBot plugin, but on the groupmember count itself. For instance, by the use of an array I want this command line:

Command Line A
/if ( ${Group.Member[5].PctHPs}<100) {
/casting "${fastheal}" ${fasthealgem} -maxtries|5 -targetid|${Group.Member[5]}
/gsay ${Group.Member[5]} has ${Target.PctHPs}%hp
} else {|||...


to function more like this command line:

Command Line B
/if (${NetBots[${NBToon${x}}].PctHPs}<=${healAt} {
/casting ${heal} gem${healGem} -maxtries|5 -targetid|${NetBots[${NBToon${x}}].ID}
/g Incoming << ${heal} >> for ${Target} ...
}
/return


Without using the NetBot plugin, I want to compile an array which uses the group member count and replaces the "5" in ${Group.Member[5]} with an "x" so as to make it more in line with ${NBToon${x}} in order to compact the script, and to use /next x before /return.

#2
I also would like to know if it is more appropriate to use brackets around the integer as it is in ${Group.Member[5]}[/1], because as you note in the variable with [i]${NBToon${x}} it has been enclosed in braces. Is the use of braces around the variable {x} proper language as compared to [x]?

#3
In Snippet B:, the following commands are present, which are not present in Snippet A::


/varset Bot TRUE

and

/varset NBToon${x} ${NetBots.Client.Token[${x}, ]}

What function do they serve, and in the second /varset line, does the blank space in [${x}, ]} following the comma have a default function?

#4

And my final question is, what's the appropriate syntax within:

/for x 1 to ${NetBots.Counts}

and:

/varset NBToon${x} ${NetBots.Client.Token[${x}, ]

If we replace the instances of "Netbots" with "Group.Member"?

Thank you very kindly for your assistance. I would like to actually learn how to script these things on my own with a little guidance rather than just be handed a functional macro, because in all honesty, I've never had as much fun playing EQ on live (started in Kunark, went to emu when GoD was released) or on any other emulator I've tried since I started working with MQ2.

I really want to get this pegged down because I'm about to take my rng(main), pal, clr, dru, shm, enc team through the actual progression: I'm getting the Kael armor, then the Kael armor upgrade at Shadowhaven and doing the automaton quests, then SSRA, so on and so forth. This server is chock full of quests and I want to be able to enjoy them ground-up, and I know that I am incapable of doing so unless I can peg down the above questions.

(As a side-note, I refused to cheese it with the AA's on the solo aura quest for Eustace and I will not proceed with it until I reach 300 tailoring. I'm currently at 286 skill, and I have enough components for 164 more Tae Ew packs. If you need a few, please hit me up in this thread or in-game.)

Re: Arrays, cleanup question.

Posted: Sun Mar 26, 2017 8:12 pm
by Denizen
Looks like you are diving in deep.

Meh I'm a bit more lazy and would type something like this at the keyboard to consent to Oaken to rez:

/bca //consent Oaken



:D

Re: Arrays, cleanup question.

Posted: Sun Mar 26, 2017 11:06 pm
by eustace11
Yeah, I'm not really concerned about the consent issue and hotkeys. I've double and triple boxed with eqwindows just using alt tab before, so...

This is just intriguing to me on how similar it was writing games in BASIC on my Atari in 1984, lol.

Re: Arrays, cleanup question.

Posted: Wed Mar 29, 2017 12:58 pm
by eustace11
I managed to do what I was trying to do.

However, I wasn't able to build an array and use a variable to compress that segment - sorely to my dismay.

Re: Arrays, cleanup question.

Posted: Sat Apr 01, 2017 9:01 am
by moguay
Hi, you can use string array with separator, ex "|", " " ...
Below an simple exemple to create a string array, they are many way to create and manage this.

Code: Select all

/for e 1 to ${Me.Bank[${i}].Container}
    /if (${Me.Bank[${i}].Item[${e}].ID} && ${Me.Bank[${i}].Item[${e}].Type.Equal[${strFindType}]}) {
        /call strArrayArg "${itemNameList}" "${Me.Bank[${i}].Item[${e}]}" "|"
        /varset itemNameList ${Macro.Return}
    }
/next e

Sub strArrayArg(string strArrayArg, string strAdd, strSeparator)
    /if (!${strArrayArg.Length}) {
        /varset strArrayArg ${strAdd}
    } else {
        /varset strArrayArg ${strArrayArg}${strSeparator}${strAdd}
    }
/return ${strArrayArg}

or a true array var, but not with a dynamic sizing

Code: Select all

/declare itemArray[33] string local

If I understand what you are trying to do. In your case, I do not create a list, but I will only look for the number and the most urgent to heal.

Re: Arrays, cleanup question.

Posted: Sat Apr 01, 2017 12:45 pm
by eustace11
Thank you so very very much!!!

Re: Arrays, cleanup question.

Posted: Sat Apr 01, 2017 8:27 pm
by moguay
Below a useful function to manage String array

Code: Select all

Sub ListDelbyArg(string sList,int sArg,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${${sList}}
    /varset splaceholder ${splaceholder.Arg[${sArg},${sDiv}]}
    /varcalc sleft  ${${sList}.Find[${sDiv}${splaceholder}${sDiv}]}
    /varset splaceholder ${splaceholder}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}} deleted arg ${sArg}
/return


Code: Select all

Sub ListReplacebyArg(string sList,string sElement,string sArg,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${${sList}}
    /varset splaceholder ${splaceholder.Arg[${sArg},${sDiv}]}
    /varcalc sleft  ${${sList}.Find[${sDiv}${splaceholder}${sDiv}]}
    /varset splaceholder ${splaceholder}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${sElement}${sDiv}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}} sElement ${sElement} repladed arg ${sArg}
/return


Code: Select all

Sub StringReplaceAll(string sList,string oldElement,string newElement)
    /declare i int local
    /declare sright int local
    /declare sleft int local
    /for i 1 to ${${sList}.Length}
        /if (${${sList}.Find[${oldElement}]}) {
            /varset ${sList} |${${sList}}||
            /varcalc sleft  ${${sList}.Find[${oldElement}]}-1
            /varcalc sright ${sleft}+${oldElement.Length}
            /varset ${sList} ${${sList}.Left[${sleft}]}${newElement}${${sList}.Right[-${sright}]}
            /varset ${sList} ${${sList}.Left[-2].Right[-1]}
        } else {
            /if (${DebugList.Find[core]}) /echo List ${${sList}} oldElement ${oldElement} replaced newElement ${newElement}
            /return
        }
    /next i
    /echo Error in StringReplaceAll
/return


Code: Select all

Sub ListDelbyName(string sList,string sName,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${sDiv}${${sList}}${sDiv}
    /varcalc sleft  ${splaceholder.Find[${sDiv}${sName}${sDiv}]}-1
    /varset splaceholder ${sName}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Deleted: ${sName}
/return ${sList}


Code: Select all

Sub ListAppendElement(string sList,string sElement,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    | Create List if not found and not array
    /if (!${sList.Find[Array]}) {
        /if (!${Defined[${sList}]}) /declare ${sList} string local
    }

    /if (${${sList}.Length}) {
        /varset ${sList} ${${sList}}${sDiv}${sElement}
    } else {
        /varset ${sList} ${sElement}
    }
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Added after: ${sElement}
/return ${sList}


Code: Select all

Sub ListPrependElement(string sList,string sElement,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /if (${${sList}.Length}) {
        /varset ${sList} ${sElement}${sDiv}${${sList}}
    } else {
        /varset ${sList} ${sElement}
    }
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Added before: ${sElement}
/return ${sList}


Code: Select all

Sub ListFindStringArg(string sList,string sString,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /declare sReturn int local
    /varcalc sReturn ${${sList}.Left[${${sList}.Find[${sString}]}].Count[${sDiv}]}+1
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Arg: ${sReturn}
/return ${sReturn}

Re: Arrays, cleanup question.

Posted: Fri Apr 07, 2017 1:04 pm
by eustace11
Thank you very much. I'm trying to set up an array that handles this so I don't have to use /goto :n jumps.

/if ( ${Group.Member[x].PctHPs}<=70 && ${Group.Member[x].PctHPs}>=50 ){
/target ${Group.Member[x]}
/delay 50
/gsay Tossing a hot on ${Target.CleanName}
/casting "Pious Elixir" -maxtries|5
} else /if (${Group.Member[x].PctHPs}<=48) {
/target ${Group.Member[x]}
/delay 50
/gsay quickie heal and big heal incoming for ${Target.CleanName}
/casting "Pious Remedy" -maxtries|3
/delay 2.3s
/casting "9190" -maxtries|3
/delay 4.5s

}

As a side note, I don't know if the /delay command will handle decimals or if it needs to be integers. This is an untested line as of this post. I'm still assembling the goto's, because I'm not able to variable the x as of yet, and the shunt back to the :Main loop cycle.

Re: Arrays, cleanup question.

Posted: Fri Apr 07, 2017 1:19 pm
by eustace11
moguay wrote:Below a useful function to manage String array

Code: Select all

Sub ListDelbyArg(string sList,int sArg,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${${sList}}
    /varset splaceholder ${splaceholder.Arg[${sArg},${sDiv}]}
    /varcalc sleft  ${${sList}.Find[${sDiv}${splaceholder}${sDiv}]}
    /varset splaceholder ${splaceholder}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}} deleted arg ${sArg}
/return


Code: Select all

Sub ListReplacebyArg(string sList,string sElement,string sArg,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${${sList}}
    /varset splaceholder ${splaceholder.Arg[${sArg},${sDiv}]}
    /varcalc sleft  ${${sList}.Find[${sDiv}${splaceholder}${sDiv}]}
    /varset splaceholder ${splaceholder}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${sElement}${sDiv}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}} sElement ${sElement} repladed arg ${sArg}
/return


Code: Select all

Sub StringReplaceAll(string sList,string oldElement,string newElement)
    /declare i int local
    /declare sright int local
    /declare sleft int local
    /for i 1 to ${${sList}.Length}
        /if (${${sList}.Find[${oldElement}]}) {
            /varset ${sList} |${${sList}}||
            /varcalc sleft  ${${sList}.Find[${oldElement}]}-1
            /varcalc sright ${sleft}+${oldElement.Length}
            /varset ${sList} ${${sList}.Left[${sleft}]}${newElement}${${sList}.Right[-${sright}]}
            /varset ${sList} ${${sList}.Left[-2].Right[-1]}
        } else {
            /if (${DebugList.Find[core]}) /echo List ${${sList}} oldElement ${oldElement} replaced newElement ${newElement}
            /return
        }
    /next i
    /echo Error in StringReplaceAll
/return


Code: Select all

Sub ListDelbyName(string sList,string sName,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /varset ${sList} ${sDiv}${${sList}}${sDiv}${sDiv}
    /declare sright int local
    /declare sleft int local
    /declare splaceholder string local ${sDiv}${${sList}}${sDiv}
    /varcalc sleft  ${splaceholder.Find[${sDiv}${sName}${sDiv}]}-1
    /varset splaceholder ${sName}${sDiv}
    /varcalc sright ${sleft}+${splaceholder.Length}
    /varset ${sList} ${${sList}.Left[${sleft}]}${${sList}.Right[-${sright}]}
    /varset ${sList} ${${sList}.Left[-2].Right[-1]}
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Deleted: ${sName}
/return ${sList}


Code: Select all

Sub ListAppendElement(string sList,string sElement,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    | Create List if not found and not array
    /if (!${sList.Find[Array]}) {
        /if (!${Defined[${sList}]}) /declare ${sList} string local
    }

    /if (${${sList}.Length}) {
        /varset ${sList} ${${sList}}${sDiv}${sElement}
    } else {
        /varset ${sList} ${sElement}
    }
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Added after: ${sElement}
/return ${sList}


Code: Select all

Sub ListPrependElement(string sList,string sElement,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /if (${${sList}.Length}) {
        /varset ${sList} ${sElement}${sDiv}${${sList}}
    } else {
        /varset ${sList} ${sElement}
    }
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Added before: ${sElement}
/return ${sList}


Code: Select all

Sub ListFindStringArg(string sList,string sString,string sDiv)
    /if (!${Defined[sDiv]}) /declare sDiv string local |
    /declare sReturn int local
    /varcalc sReturn ${${sList}.Left[${${sList}.Find[${sString}]}].Count[${sDiv}]}+1
    /if (${DebugList.Find[core]}) /echo List ${${sList}}  Arg: ${sReturn}
/return ${sReturn}



All this that you've shown me in comparison to what I wrote,

/if ( ${Group.Member[x].PctHPs}<=70 && ${Group.Member[x].PctHPs}>=50 ){
/target ${Group.Member[x]}
/delay 50
/gsay Tossing a hot on ${Target.CleanName}
/casting "Pious Elixir" -maxtries|5
} else /if (${Group.Member[x].PctHPs}<=48) {
/target ${Group.Member[x]}
/delay 50
/gsay quickie heal and big heal incoming for ${Target.CleanName}
/casting "Pious Remedy" -maxtries|3
/delay 2.3s
/casting "9190" -maxtries|3
/delay 4.5s

}


It all really brings me back to the 2nd grade, recording on magnetic tape, and using a dialup peer to peer connection on the Atari800xl with a friend. That was 1986, and it really amuses me to see that the language above is undeniably a dialect of BASIC.

Re: Arrays, cleanup question.

Posted: Sat Apr 08, 2017 1:39 pm
by moguay
Capture the moment to make a heal, not required an array.
You need to check quickly all the group and extract only the priority.

For exemple you can classify by hp and cast it by priority if found

Below just a draft code :

Code: Select all

/varset lower70 int local 70
/varset lower70toon string local
/varset lower50 int local 50
/varset lower70toon string local

/for x 0 to ${Group.Members}
    if ${Group.Member[x].PctHPs} > 50 && ${Group.Member[x].PctHPs} < ${lower90}) {
        /varset lower70 ${Group.Member[x].PctHPs}
        /varset lower70toon ${Group.Member[x]}
    }
    if ${Group.Member[x].PctHPs} < ${lower50}) {
        /varset lower50 ${Group.Member[x].PctHPs}
        /varset lower50toon ${Group.Member[x]}
    }   
/next x

/if (${Spawn[pc ${lower50toon}].ID}) { casting 50hp... }
/if ({Spawn[pc ${lower70toon}].ID}) { casting 70hp... }