Moderator: MacroQuest Developers
Ok, here is the code I am using:Lax wrote: It might be better to give me a code sample of what you're trying to do
Code: Select all
objectdef InvPack
{
variable byte slot
method Open()
{
if (!${Window[pack${This.slot}].Open} && ${This.IsSlotValid})
{
nomodkey EQitemnotify pack${This.slot} rightmouseup
}
}
method Close()
{
if (${Window[pack${This.slot}].Open} && ${This.IsSlotValid})
{
nomodkey EQitemnotify pack${This.slot} rightmouseup
}
}
member ToText()
{
if (${This.IsSlotValid})
{
return pack${This.slot}
}
return pack99
}
member:string GetIndex(int ID)
{
if (${This.IsSlotValid} && ${ID} >= 1 && ${ID} <= ${InvSlot[${This.ToText}].Item.Container})
{
return ${InvSlot[${This.ToText}].Item.Item[${ID}]}
}
return NULL
}
member:bool IsSlotValid()
{
if (${This.slot} >= 1 && ${This.slot} <= 8 && ${InvSlot[pack${This.slot}].Item.Container} > 0)
{
return TRUE
}
return FALSE
}
}
objectdef Inventory
{
variable InvPack packs[8]
method Initialize()
{
variable byte slot = 0
while (${slot:Inc} <= 8)
{
packs[${slot}].slot:Set[${slot}]
}
}
member:InvPack Pack(int x)
{
if (${x} >= 1 && ${x} <= 8)
{
return packs[${x}]
}
}
method Open()
{
variable byte slot = 0
while (${slot:Inc} <= 8)
{
packs[${slot}]:Open
}
}
method Close()
{
variable byte slot = 0
while (${slot:Inc} <= 8)
{
packs[${slot}]:Close
}
}
}
Code: Select all
variable string xmlSettingsFile = ${LavishScript.HomeDirectory}/Scripts/fishing/fishing.xml
variable collection:int items
variable collection:int poles
variable Inventory inventory
function main()
{
ext -require ISXEQ
call init
call checkPole
}
function init()
{
variable string poleSet = SettingXML[${xmlSettingsFile}].Set["Fishing Poles"]
variable byte x = 0
variable string myPole
/* Gather up all fishing pole data */
while (${x:Inc} <= ${${poleSet}.Keys})
{
poles:Set[${${poleSet}.Key[${x}]}, ${x}]
}
}
function checkPole()
{
if (!${InvSlot[mainhand].Item.Type(exists)} || ${InvSlot[mainhand].Item.Type.NotEqual[Fishing Pole]})
{
variable int poleSlot = 0
if (${poles.FirstKey(exists)})
{
do
{
poleSlot:Set[${FindItem[=${poles.CurrentKey}].InvSlot}]
if (${poleSlot} > 0)
{
Break
}
}
while (${poles.NextKey(exists)})
}
variable InvPack ff = inventory.Pack[1]
;ff.slot:Set[3]
echo ${ff}
;echo ${inventory.Pack[1]}
}
}
Not in this fashion.Is it even possible to return an objectdef intact?
Code: Select all
member:InvPack Pack(int x)
{
if (${x} >= 1 && ${x} <= 8)
{
return packs[${x}]
}
} Code: Select all
variable InvPack Returning=packs[1]Code: Select all
member:variable Pack(int x)
{
if (${x} >= 1 && ${x} <= 8)
{
return packs[${x}]
}
} Code: Select all
member:variable Pack(int x)
{
return packs[${x}]
} Yes, that is exactly what I want.. a reference to the previously created InvPack... unfortunately I can't get it :)Lax wrote: What you're wanting to do is pass the value by reference, not create a new object. To pass by reference, use the "variable" type, which can be initialized with the name of any currently in-scope variable. The variable can go out of scope, e.g. calling another function with a reference to a local variable works just fine. However, it will cause a crash if the variable was DESTROYED instead of simply being out of scope
Code: Select all
member:variable Pack(int x) { if (${x} >= 1 && ${x} <= 8) { return packs[${x}] } }
Code: Select all
variable InvPack i = inventory.packs[2]
Code: Select all
InvPack:Inventory[inventory.packs[2]]
Code: Select all
variable InvPack i = 2
Code: Select all
inventory.Packs[2]
Code: Select all
member:variable Pack(int x)
{
echo X: ${x}
return packs[${x}]
}
Code: Select all
echo ${inventory.Packs[2]}
You setup a member 'Pack' but are trying to test it by calling .Packs[] ?kellewic wrote:I can't really figure out what's going on... the following:
isn't even being called when I do:Code: Select all
member:variable Pack(int x) { echo X: ${x} return packs[${x}] }
There is not 'X: 2' being echo'dCode: Select all
echo ${inventory.Packs[2]}
I would expect ' echo ${inventory.Packs[2]}' to output 'pack2' via InvPack's GetText, which I assume is called when you echo an object kind of like Java's toString().
Yeah, I am retarded on that one. Code typo. When I correct it, it now gives:iluvseq wrote: You setup a member 'Pack' but are trying to test it by calling .Packs[] ?
ie: echo ${inventroy.Packs[2]} won't be calling the member Pack, so your echo X line won't get called...
I'm sure it's not entirely that simple, but it does look like part of the problem, from here...
Code: Select all
Could not initialize variable object for function return value
Dumping script stack
--------------------
-->C:/Program Files/InnerSpace/Scripts/Packs.inc:74 Atom00000328() {
C:/Program Files/InnerSpace/Scripts/fishing.iss:151 checkPole() inventory.Pack[2]:Open
C:/Program Files/InnerSpace/Scripts/fishing.iss:60 main() call checkPole