[09 Aug 2009] RemoveItem()

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
GMKai
Posts: 158
Joined: Mon Feb 15, 2010 10:58 am

[09 Aug 2009] RemoveItem()

Post by GMKai »

Note: This is an archived post that was originally sent to the Hollywood mailing list on 09 Aug 2009 14:54:30 +0000

Hello,

was it already known that there is a problem with RemoveItem() when doing this on the first item? If there is only one row the example below works too. What makes me wondering too, is that I have to bring in another helpervariable to make it work for any other row than the first. If not, this codesnippet fails when removing the first row, whenever there is more than one row:

Code: Select all

Function p_RemoveClub()
    Local id = StringRequest("Enter ID","Enter ID of Club to remove","0")
    If (id <> "" AND id <>"0")
       If ClubCount > 0
          For i = 0 To ClubCount-1
              If ToString(t_club[i][0]) = id
                 /*Entry To be removed got identified*/
                 y = i
                 For t=(ListItems(t_club[y])-1) To 0 Step -1
                   RemoveItem(t_club[y])
                 Next
                 ClubCount = Sub(ClubCount,1)
                 Break
              ElseIf(t_club[i][0] > id)
                 Break
              EndIf
          Next
       EndIf()
    EndIf()
EndFunction 
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[12 Aug 2009] Re: RemoveItem()

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 12 Aug 2009 00:28:24 +0200
Hello,

was it already known that there is a problem with RemoveItem() when doing this on the first item? If there is only one row the example below works too. What makes me wondering too, is that I have to bring in another helpervariable to make it work for any other row than the first. If not, this codesnippet fails when removing the first row, whenever there is more than one row:
I'd bet that there's a mistake in your code because RemoveItem() is a lua function and this shouldn't have any problems.. if you still think that there's a bug in RemoveItem(), please provide a smaller code snippet. The one you provided is too complicated and I don't really know what it does. Try to break it down :)
GMKai
Posts: 158
Joined: Mon Feb 15, 2010 10:58 am

[12 Aug 2009] re: removeitem()

Post by GMKai »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 12 Aug 2009 15:22:16 +0200

Hello guys,

when stripping down the example, I got some strange behaviour. When removing the only row of a table, it is removed with the respective value. When adding two rows and removing the first again, the returnvalue is nil... please have a look:

Code: Select all

@VERSION 4,0

CtrlCQuit(True)
EscapeQuit(False)
EnableLayers()

Function p_defTab(tabname,n,x,y)
    For i = n To x-1
        tabname[i] = {}
        For j = 0 To y
            tabname[i][j] = "0"
        Next
    Next
EndFunction

Function p_delTabrow()
    For i = 0 To 5
        e = RemoveItem(t_masterdata[0])
        Print(i," ..  ",e,"\n")
    Next
EndFunction

/*FLOW BEGINS:  !!*/

/*define empty table*/

Global t_masterdata = {}

/*Add one row*/
p_defTab(t_masterdata,ListItems(t_masterdata),(ListItems(t_masterdata)+1),5)

/*remove one row*/
Print("START REMOVING\n")
p_delTabrow()

/*Add two rows*/
p_defTab(t_masterdata,ListItems(t_masterdata),(ListItems(t_masterdata)+1),5)
p_defTab(t_masterdata,ListItems(t_masterdata),(ListItems(t_masterdata)+1),5)

/*remove one row*/
Print("\nSTART REMOVING again\n")
p_delTabrow()

Print("\nPress LMB to exit")
WaitLeftMouse()
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[13 Aug 2009] Re: re: removeitem()

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 13 Aug 2009 00:24:54 +0200
Hello guys,

when stripping down the example, I got some strange behaviour. When removing the only row of a table, it is removed with the respective value. When adding two rows and removing the first again, the returnvalue is nil...
It is Nil because you're not removing the row table. You are removing just the elements of the row table but not the table itself. Remember that you have a two dimensional table! Here's how it must look:

Code: Select all

Function p_delTabrow()
    For i = 0 To 5
        e = RemoveItem(t_masterdata[0])
        Print(i," ..  ",e,"\n")
    Next
   ;*******************************************************
   RemoveItem(t_masterdata, 0)   ; add this and it will work
   ;*******************************************************
EndFunction
Locked