Saturday, January 1, 2011

Furniture 2, New Year




Got Drag and Drop up for moving from player items to furniture array. Drag and drop is just so dull... for those of you wondering why its basically just positioning x y coordinates and then finessing them. Time consuming and then there was a number odd bugs that popped up the one I still don't get is the cleaner array not working.

My normal code for cleaning array (just change the name of the array):

//cleans the furnitureImageArray
function roomFurnitureClean(){
for (var i:Number = 0; i < furnitureImageArray.length; i++) {
if (furnitureImageArray.length != 0) {
removeChild(furnitureImageArray[i]);
furnitureImageArray.splice(0,1);
i = -1;
}
}
}

now the furniture array is actually made up of possible nulls and objects.

Example [object furnitureHousePlant],,,,[object furnitureBed],,,,[object furniturepiano]

So I modified to:

//cleans the furnitureImageArray
function roomFurnitureClean(){
for (var i:Number = 0; i < furnitureImageArray.length; i++) {
if (furnitureImageArray.length != 0) {
if (furnitureImageArray[i] != null {
removeChild(furnitureImageArray[i]);
}
furnitureImageArray.splice(0,1);
i = -1;
}
}
}

Which should have fixed it but for some reason it would never delete the last object and instead of crash and I still don't know why. But if you don't know why just use a different method my fix.

//cleans the furnitureImageArray
function roomFurnitureClean(){
var total:int = new int(0);
for (var i:Number = 0; i < furnitureImageArray.length; i++) {
if (furnitureImageArray.length != 0) {
if (furnitureArray[total] != -1) {
removeChild(furnitureImageArray[i]);
}
furnitureImageArray.splice(0,1);
i = -1;
total++;
}
}
}

That's right I'm totaling the spot from the array that actually holds what each furniture is. But I have no idea why that was necessary... oh well it works.

Add that to another bug that was just pure stupidity on my part but took forever to find and that was how I spent my new years eve.

Happy New Year.

Daisy

6 comments:

  1. I think the second code has a typo in it, I'm not exactly sure what it's supposed to do...it's easy to get things confused when you make loops like this.

    So, the point is to delete everything from the array, but make sure that you call removeChild on it first?

    It might be easier to use a while loop:

    while (furnitureImageArray.length > 0)
    {
    removeChild(furnitureImageArray[0]);
    furnitureImageArray.splice(0,1);
    }

    Or, you could go through and call removeChild on every element in the array. Then you can just delete the array.

    for (var i:Number = 0; i < furnitureImageArray.length; i++)
    {
    removeChild(furnitureImageArray[i]);
    }
    furnitureImageArray = new Array(); // just delete/recreate it

    I think those bits should work...good luck!

    ReplyDelete
  2. Obviously the second one didn't work like I said.

    But

    for (var i:Number = 0; i < furnitureImageArray.length; i++)
    {
    removeChild(furnitureImageArray[i]);
    }

    will crash because you cant remove child on a null.

    ie

    [object furnitureHousePlant],,,,[object furnitureBed],,,,[object furniturepiano]

    all the little ,, are nulls and removing something that doesn't exist crashes flash.

    also I'm lazy its a global array because its passed into dozens of functions. Don't want to really remove just want it to be empty so its not taking up space when not used.

    Though I think your while code is probably cleaner then my version.

    Daisy

    ReplyDelete
  3. how about instead of deleting you fill every position of the array with empty or null objects (objects that contain nothing)?

    ReplyDelete
  4. some other problem: i experienced a problem with getting girls pierced. in about 50% of the cases i try to pierce a girl, i get her pierced but i still can't apply piercings (especially ears and clit).
    i have no idea if there's a connection between this problem and my much more severe problem. i now can't load my saved game any more. after experiencing the piercing problem i saved and started the game again, to see if something changes, but i can only start a new game now. if i click on options or continue first i can't even do this any more.

    ReplyDelete
  5. ah, if you cant remove a null, then you just have to make it not null just before applying the remove.
    something like this:

    while (furnitureImageArray.length > 0)
    {
    if (furnitureImageArray[i] = null {
    furnitureImageArray[i] = something;
    }
    removeChild(furnitureImageArray[0]);
    furnitureImageArray.splice(0,1);
    }

    ReplyDelete
  6. code is theoretically sound in the last 2 posts but 2 things

    while (furnitureImageArray.length > 0)
    {
    if (furnitureImageArray[i] != null {
    removeChild(furnitureImageArray[0]);
    }
    furnitureImageArray.splice(0,1);
    }

    may be more efficient for computer to perform
    as it will remove a step on null objects instead of adding it also whats with
    the

    i=-1;

    i don't understand why you are setting i to negative 1. perhaps you meant

    i-=1;

    which decrements by 1. aka shorter way for decrementing by 1.

    i--;

    if i remember correctly anyway.

    by The pheonix

    ReplyDelete