Kill last created

coleislazy

  • *
  • Posts: 2607
Hopefully, you can drop those two lines into a code block (changing the attribute names to match yours) and it will work.

But this is the first time I've ever even SEEN Objective-C code, so I don't know if I got it right. Fingers crossed for you!

zerosimms

  • Posts: 710
Then I guess there's only one way to find out :-)

zerosimms

  • Posts: 710
Code: [Select]
Behavior: Design_0_0_CreateSomeBirds at line 81
Label must be a simple identifier.
            _MyActorAttribute = [_birds]: objectAtIndex: ([_birds] }count] - 1)] [_birds] removeLastObject];

Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting rightparen before rightbrace.
            _MyActorAttribute = [_birds]: objectAtIndex: ([_birds] }count] - 1)] [_birds] removeLastObject];

Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting identifier before rightbracket.
            _MyActorAttribute = [_birds]: objectAtIndex: ([_birds] }count] - 1)] [_birds] removeLastObject];

Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting identifier before rightbracket.
            _MyActorAttribute = [_birds]: objectAtIndex: ([_birds] }count] - 1)] [_birds] removeLastObject];

Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting identifier before rightbracket.
            _MyActorAttribute = [_birds]: objectAtIndex: ([_birds] }count] - 1)] [_birds] removeLastObject];

Umm... Think I'm getting somewhere with it but loads of syntax errors.
Is there a Objective C syntax checker I can use somewhere?
When I manually make changes I seem to make it worse

Alexin

  • *
  • Posts: 3130
Code: [Select]
_MyActorAttribute = [_MyActorsList objectAtIndex: ([_MyActorsList count] - 1)];
[_MyActorsList removeLastObject];

Use the larger code block, for readability,  and paste exactly the code above in it (replacing the attributes with your own, like you did).

The code coleislazy posted was (probably) missing a semicolon.
"Find the fun"
alexin@stencyl.com

zerosimms

  • Posts: 710
Good point :-) The larger code block makes it much easier to read!

Ok, so I copied it in and this is the result when compiling:

Code: [Select]
Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting rightbracket before objectAtIndex.
            _MyActorAttribute = [_birds objectAtIndex: ([_birds count] - 1)];

Behavior: Design_0_0_CreateSomeBirds at line 81
Syntax error: expecting rightbrace before rightparen.
            _MyActorAttribute = [_birds objectAtIndex: ([_birds count] - 1)];

I tried making the changes that it suggest I.E. putting a ']' before objectAtIndex but this just causes more errors, so it actually ends up worse... :-(



 

Alexin

  • *
  • Posts: 3130
Post the generated code, please.
"Find the fun"
alexin@stencyl.com

zerosimms

  • Posts: 710
Here is the code when I hit 'preview' oddly I cant see the code I've added:

Code: [Select]
package scripts
{
import flash.display.BlendMode;
import flash.events.*;
import flash.net.*;
import flash.filters.*;

import Box2DAS.Collision.*;
import Box2DAS.Collision.Shapes.*;
import Box2DAS.Common.*;
import Box2DAS.Dynamics.*;
import Box2DAS.Dynamics.Contacts.*;
import Box2DAS.Dynamics.Joints.*;

import stencyl.api.data.*;
import stencyl.api.engine.*;
import stencyl.api.engine.actor.*;
import stencyl.api.engine.behavior.*;
import stencyl.api.engine.bg.*;
import stencyl.api.engine.font.*;
import stencyl.api.engine.scene.*;
import stencyl.api.engine.sound.*;
import stencyl.api.engine.tile.*;
import stencyl.api.engine.utils.*;

import org.flixel.*;

public dynamic class Design_0_0_CreateSomeBirds extends SceneScript
{

public var _birds:Array;
public var _bird1:Array;
public var _bird2:Array;
public var _bird3:Array;
public var _bird4:Array;
public var _bird5:Array;
public var _bird6:Array;
public var _bird8:Array;
public var _bird7:Array;
public var _bird9:Array;
public var _bird10:Array;
public var _MyActorAttribute:Actor;
override public function init():void
{
    doesCustomDrawing();
    ArrayUtil.empty(_birds as Array);
    setGameAttribute("timer", 5);
    runPeriodically(1000 * 1, function(timeTask:TimedTask):void {
        setGameAttribute("timer", ((getGameAttribute("timer") as Number) - 1));

        if (((getGameAttribute("timer") as Number) < = 0))
        {
            setGameAttribute("timer", 0)
            ;
        } });

    for (var index0:int = 0; index0 < randomInt(Math.floor(4), Math.floor(10)); index0 + +)
    {
        createActor(getActorType(1), randomInt(Math.floor(88), Math.floor(150)), randomInt(Math.floor(130), Math.floor(189)), FRONT);
        _MyActorAttribute = getLastCreatedActor();
        _birds.push(((getGameAttribute("NumberOfBirds") as Number) + 1));
    }
}
override public function update():void
{

    if (isMousePressed())
    {
        ArrayUtil.removeAt(_birds, ((getGameAttribute("NumberOfBirds") as Number) - 1));
        getLastCreatedActor().setAnimation("blood".toString());
        _MyActorAttribute = [_birds objectAtIndex: ([_birds count] - 1)];
        [_birds removeLastObject];
        !ERROR!.say("Explode Actor", "explode");
    }
}
override public function draw(g:Graphics, x:Number, y:Number):void
{
    g.setFont(getFont(3));
    g.drawString("" + _birds.length, 97, 68);
}

public function Design_0_0_CreateSomeBirds(ignore:*, scene:GameState)
{
super(scene);
nameMap["birds"] = "_birds";
nameMap["bird1"] = "_bird1";
nameMap["bird2"] = "_bird2";
nameMap["bird3"] = "_bird3";
nameMap["bird4"] = "_bird4";
nameMap["bird5"] = "_bird5";
nameMap["bird6"] = "_bird6";
nameMap["bird8"] = "_bird8";
nameMap["bird7"] = "_bird7";
nameMap["bird9"] = "_bird9";
nameMap["bird10"] = "_bird10";
nameMap["MyActorAttribute"] = "_MyActorAttribute";

}

override public function forwardMessage(msg:String):void
{

}
}
}

I've also attached the logs, thank you for helping me, I'm most grateful!

Alexin

  • *
  • Posts: 3130
LOL. Since you're an iStencyl Tester I assumed the game was for iOS and the game was coded in Objective-C. However, the code you posted is clearly AS3 (Flash).

Code: [Select]
_MyActorAttribute = _MyActorsList.pop() as Actor;

That code gets the last actor on the list, assigns it to the attribute "My Actor Attribute" and removes it from the list.


Coleislazy was right from the beginning. I apologize for the confusion.
"Find the fun"
alexin@stencyl.com

zerosimms

  • Posts: 710
Ahh, I was planning (down the line) to convert it to Iphone, I'm having a lot of issues converting my other game for the Iphone so this was my "break away" from it for a bit, I wanted something really simple to make that I could get on the app store to learn about from App store submission/stats/etc

Never simple though :-)

I'll try the Cole's code! Thanks again for your help, I'll try you code again in a few days when I try and get it running on my iphone!

coleislazy

  • *
  • Posts: 2607
Well, I'm glad we got this sorted out! And the .pop() method does work. I tested it right before I posted it the other day. Let us know if you have any more problems!

zerosimms

  • Posts: 710
Guys thank you all for your help and advice on this!