[04 Aug 2006] Use of RemoveItem Command

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
NathanH
Posts: 128
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

[04 Aug 2006] Use of RemoveItem Command

Post by NathanH »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 4 Aug 2006 14:48:13 -0600

Hi,

I've been using the following code to shuffle a deck of cards with the commented out section used to remove the previous choice from the list of possible cards remining to be randomly selected. Upon perusing the AmigaGuide file it appears that the RemoveItem command could replace those three lines of code.

Code: Select all

for local i=1 to qty
    tblChoice[i]=i
next

; Randomly choose from choices
for i=1 to qty
    id = rnd(qty+1-i) + 1
    tblDeck.render[i]=tblChoice[id]

   ; Remove choice and shrink possible choices by 1
    junk=REMOVEITEM(tblChoice,id)

    ; I thought that the above REMOVEITEM code would replace the following three lines but it does something different
    ;for j=id to qty-i
    ;    tblChoice[j]=tblChoice[j+1]
    ;next
next
This is kind of an odd question but what is RemoveItem doing here that is different then the code that is being replaced? I figured it would remove the indicated item from the table and roll the remaining items to one lower table index exactly as coded in the "for j" loop.

Thanks!

Nathan
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[05 Aug 2006] Re: Use of RemoveItem Command

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 05 Aug 2006 11:22:08 +0200

The problem is that your tblChoice table has no item at index 0, i.e. tblChoice[0] is NIL. RemoveItem() then automatically stops at index 0 because it is NIL. If you want to use RemoveItem() on a table, make sure this table starts at 0 and not at 1.
NathanH
Posts: 128
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

[05 Aug 2006] Re: Use of RemoveItem Command

Post by NathanH »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 5 Aug 2006 10:00:04 -0600

Thanks, I should have figured the ones-based arrays was the issue myself.
NathanH
Posts: 128
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

[05 Aug 2006] Re: Use of RemoveItem Command

Post by NathanH »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 5 Aug 2006 11:42:39 -0600

Hi,

I changed all my tables/arrays to be zero-based which, in the process, changed all the sprite IDs accordingly. What I noticed, however, is that when I use FREESPRITE(0) all of the sprites are freed. My expectation was that only sprite 0 would be freed. I can get around this issue by adding one to every sprite id when it is created.

I wasn't sure if this was a misbehavior or an undocumented feature so thought that I'd bring it up. For comparison purposes, I decided to make all object ids zero-based but received a message that interval ids needed to be positive. I received no such error when making a sprite id equal to zero. Thanks.

Nathan
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[05 Aug 2006] Re: Use of RemoveItem Command

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 05 Aug 2006 20:36:21 +0200
Hi,

I changed all my tables/arrays to be zero-based which, in the process, changed all the sprite IDs accordingly. What I noticed, however, is that when I use FREESPRITE(0) all of the sprites are freed. My expectation was that only sprite 0 would be freed. I can get around this issue by adding one to every sprite id when it is created.

I wasn't sure if this was a misbehavior or an undocumented feature so thought that I'd bring it up. For comparison purposes, I decided to make all object ids zero-based but received a message that interval ids needed to be positive. I received no such error when making a sprite id equal to zero.
Oh, wow, another bug :-(

All IDs must always be > 0. This should be somewhere in the documentation but normally Hollywood should not even allow you to create objects with IDs < 1. But it seems that this is not checked everywhere it should be.

IDs < 1 are heavily used internally by Hollywood, so that its functions will misbehave if you use them. E.g. FreeSprite(0) is not meant to free all sprites at all... it's a misbehaviour caused by the zero ID.

Anyway, thanks for the report. I'll do a fix for it. The next version of Hollywood will probably allow any IDs including strings and real numbers. But currently, you may only use IDs > 0.
Locked