Help populating arrays

BackseatScripter

Active Member
Is there a way to set all elements of an array line, in a single command?

i.e. The fishing macro has an array called Fishlist

variable(script) Fishlist Fishes[50]
variable string FishName = "Squid"
variable string Combo1 = "u"
variable string Combo2 = "d"
variable string Combo3 = "l"
variable string Combo4 = "r"
variable string Combo = "xxxx"
;
objectdef Fishlist
{
method Initialize()
{
Name:Set["Empty"]
Combo1:Set["Empty"]
Combo2:Set["Empty"]
Combo3:Set["Empty"]
Combo4:Set["Empty"]
}
method Clear()
{
Name:Set["Empty"]
Combo1:Set["Empty"]
Combo2:Set["Empty"]
Combo3:Set["Empty"]
Combo4:Set["Empty"]
}
variable string Name
variable string Combo1
variable string Combo2
variable string Combo3
variable string Combo4
}

To update each element of the array line it currently uses the following code

Fishes[${Return}].Name:Set[${FishName}]
Fishes[${Return}].Combo1:Set[${Combo1}]
Fishes[${Return}].Combo2:Set[${Combo2}]
Fishes[${Return}].Combo3:Set[${Combo3}]
Fishes[${Return}].Combo4:Set[${Combo4}]

were Return is an integer (1-50)

Is there a way to do something like:

Fishes[1]:Set["Trout",${Combo1},${Combo2},${Combo3},${Combo4}]

and put in a line at a time?
 

BackseatScripter

Active Member
No urgency on this now.

I've used the heavy mallet approach and hard coded each element.

Still if anyone kows the answer I'd be interested to hear it.
 

Amadeus

The Maestro
Staff member
Well, in C++ I would create a custom object for a "Fish" and then populate the "Fishlist" array using that custom object ...something like this:
Code:
class Fish
{
public:
 
    std::string Name;
    std::string Combo1;
    std::string Combo2;
    std::string Combo3;
    std::string Combo4;
};
 
class FishList
{
public:
    std::vector<Fish*> Fishes;
};
However, I cannot find any documentation on the lavishscript wiki on how one populates an array with a custom datatype object (that is created with lavishscript), so the method below is not terribly elegant. I'm sure it's possible to do it with a custom "Fish" object, and then just have one array of "Fish" objects (either using an 'index' or a fixed 'array'), but I do not see it documented anywhere and the guesses I tried did not work.

Either way though, the solution below does work quite well and should be easy to follow.

Code:
variable(script) FishList MyFishList

objectdef FishList
{
	method Initialize()
	{
		; Setting this to zero by default in case someone uses the object without initializing it (in which case it would be zero anyway)
		Count:Set[0]
	}
	member:int Used()
	{
		return ${Count}
	}	
	member:int GetIndexByFishName(string FishName)
	{
		variable int i = 1
		do
		{
			if ${Names[${i}].Equal[${FishName}]}
				return ${i}
		}
		while ${i:Inc} <= ${Count}	
		
		return -1
	}
	member:string Name(int Index)
	{
		return ${Names.Get[${Index}]}
	}
	member:string Combo1(int Index)
	{
		return ${Combo1s.Get[${Index}]}
	}
	member:string Combo2(int Index)
	{
		return ${Combo2s.Get[${Index}]}
	}
	member:string Combo3(int Index)
	{
		return ${Combo3s.Get[${Index}]}
	}
	member:string Combo4(int Index)
	{
		return ${Combo4s.Get[${Index}]}
	}				
	
	method Add(string sName="Empty",string sCombo1="Empty",string sCombo2="Empty",string sCombo3="Empty",string sCombo4="Empty")
	{
		; resize indexes
		Count:Inc
		Names:Resize[${Count}]
		Combo1s:Resize[${Count}]
		Combo2s:Resize[${Count}]
		Combo3s:Resize[${Count}]
		Combo4s:Resize[${Count}]
		
		; Add Fish
		Names:Set[${Count},${sName}]
		Combo1s:Set[${Count},${sCombo1}]
		Combo2s:Set[${Count},${sCombo2}]
		Combo3s:Set[${Count},${sCombo3}]
		Combo4s:Set[${Count},${sCombo4}]
	}
	
	
	variable index:string Names
	variable index:string Combo1s
	variable index:string Combo2s
	variable index:string Combo3s
	variable index:string Combo4s
	variable int Count
}

function main()
{
	variable int iAmaFish
	variable int iCount = 1
	
	MyFishList:Initialize
	MyFishList:Add["Squid","u","d","l","r"]
	MyFishList:Add["Starfish","d","l","l","u"]
	MyFishList:Add["Amafish","u","u","u","u"]

	
	;; Ex. 1
	echo "Fish 1: ${MyFishList.Name[1]}, ${MyFishList.Combo1[1]}, ${MyFishList.Combo2[1]}, ${MyFishList.Combo3[1]}, ${MyFishList.Combo4[1]}"
	echo "Fish 2: ${MyFishList.Name[2]}, ${MyFishList.Combo1[2]}, ${MyFishList.Combo2[2]}, ${MyFishList.Combo3[2]}, ${MyFishList.Combo4[2]}"
	echo "Fish 3: ${MyFishList.Name[3]}, ${MyFishList.Combo1[3]}, ${MyFishList.Combo2[3]}, ${MyFishList.Combo3[3]}, ${MyFishList.Combo4[3]}"
	echo "---"
	
	;; Ex 2 (same thing)
	do
	{
		echo "Fish ${iCount}: ${MyFishList.Name[${iCount}]}, ${MyFishList.Combo1[${iCount}]}, ${MyFishList.Combo2[${iCount}]}, ${MyFishList.Combo3[${iCount}]}, ${MyFishList.Combo4[${iCount}]}"
	}
	while ${iCount:Inc} <= ${MyFishList.Used}
	echo "---"

	;; Ex. 3
	iAmaFish:Set[${MyFishList.GetIndexByFishName[Amafish]}]
	if ${iAmaFish} > 0
		echo "Fish 'Amafish': ${MyFishList.Name[${iAmaFish}]}, ${MyFishList.Combo1[${iAmaFish}]}, ${MyFishList.Combo2[${iAmaFish}]}, ${MyFishList.Combo3[${iAmaFish}]}, ${MyFishList.Combo4[${iAmaFish}]}"
}
I should point out that this rather simple example assumes that you will not be wanting to remove any of the fish from the fishlist (although modifying should be fairly easy and straightforward.) Not that removing isn't possible ....I just didn't put anything in there for it.
 

CyberTech

Second-in-Command
Staff member
From EVEBot core/obj_BaseClass (thje sorting class), this is how you use a script defined object inside an index. Note the initialize line which lets you set the member elements as one. You could also add an Update method to obj_session, which would allow you to call temps.Value:Update[val1, val2,...] as needed.

Code:
Example Usage:
****        objectdef obj_session
****        {
****            variable int Lastping
****            variable string SessionName
****            
****            method Initialize(string sessname, int ping)
****            {
****                Lastping:Set[${ping}]
****                SessionName:Set[${sessname}]
****            }
****                
****        }
****        
****        objectdef obj_Main
****        {
****            variable index:obj_session sessionlist
****        
****            method Initialize()
****            {
****                sessionlist:Insert["session01", 4]
****        
****                sessionlist:Insert["session01", 3]
****                sessionlist:Insert["session20", 20]
****                sessionlist:Insert["session11", 11]
****                sessionlist:Insert["session34", 34]
****                sessionlist:Insert["session22", 22]
****                sessionlist:Insert["session03", 1]
****                sessionlist:Insert["session44", 44]
****                sessionlist:Insert["session04", 0]
****            
****                variable iterator temps
****                sessionlist:GetIterator[temps]
****                if ${temps:First(exists)}
****                do
****                {
****                    echo ${temps.Value.SessionName}: ${temps.Value.Lastping}
****                }
****                while ${temps:Next(exists)}
****            }
****        }    
*/
 
Last edited:
Top Bottom