Code: Select all
class Container {
_bannedElements := []
elementList := []
__New() {
}
elements() {
this.elementList := []
elementList := []
loop, 10
{
random, rand, 1, 10
element := new Element(rand)
if (!element)
msgbox % "no element`naddress: " element.address "`nisObject: " isObject(element) "`ntest: " element.test
if (!this.helloIsBanned(element))
elementList.push(element)
}
this.elementList := elementList
return this.elementList
}
helloIsBanned(elem) {
for key, element in this._bannedElements
{
if (element.address = elem.address)
return true
}
return false
}
banElement(element) {
this._bannedElements.push(element.address)
}
removeBans() {
this._bannedElements := []
}
}
class Element {
address := 0
test := 123
__New(address) {
this.address := address
}
}
container := new Container()
elements := container.elements()
msgbox % "First list of elements`n`n" obj2String(elements)
sleep, 100
bannedNumber := elements[2]
container.banElement(elements[2])
sleep, 100
elements := container.elements()
msgbox % "List of elements after ban of number: " bannedNumber "`n`n" obj2String(elements)
container.removeBans()
elements := container.elements()
msgbox % "List of elements after removing ban`n`n" obj2String(elements)
Obj2String(Obj,FullPath:=1,BottomBlank:=0, delimiter := "`n")
{
static String,Blank
if (FullPath=1)
String:=FullPath:=Blank:=""
if (IsObject(Obj)) {
for key, value in Obj {
if (IsObject(value))
Obj2String(value, FullPath "." key, BottomBlank)
else {
if (BottomBlank=0)
String .= FullPath "." key " = " value delimiter
else if (value != "")
String .= FullPath "." key " = " value delimiter
else
Blank .= FullPath "." key " =" delimiter
}
}
}
return String Blank
}
It should these things in the following order:
1. Show a list of elements
2. Ban an element (this prevents it from being added to the list the next time we request a list of elements)
3. Show a list of elements again without any banned element
4. Remove the ban
5. Show a list of elements again
What it does
It does these things in the following order:
1. Shows a list of elements in the msgbox
2. Bans an element (this prevents it from being added to the list the next time we request a list of eleemnts)
3. 10 msgboxes are thrown showing that the the new Element() failed and the var is empty. The msgbox shows an empty list, sometimes this list has 1 element
4. Removes the ban (I think)
5. Shows an empty list, sometimes this list has 8 empty elements
What I tried
I think this is related to the references of the objects but I don't see how this can affect the script in a way that it is not able to create a new class anymore.