A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Changing Values [Script]

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2

    Changing Values [Script]

    Hi, I'm new to flash programming. I'm programming a game in Actionscript 2.0 and I'm having some issues. I have a robot walking through the inside of a ship that uses a grid system. I have it programmed so that when the robot is moving left it will check if the box to the left is one of the two types of boxes that can be entered if not then it will check if the robot has hit that box and if so will keep you from moving.

    So here's where it gets tricky. My robot seems to move through walls and randomly stop when hitting certain boxes (but not the right ones). What's even worse is I put up some debugging messages and they are telling me that the boxes to the left of the robot, the one's it has been checking, have values that are simply strange and not the original ones I assigned them. Some of the boxes on the right side are even giving me "undefined" as the result. I also put up a debugging message for the hit Test and that too seems to be random. Of course it is giving me true when it stops the robot but most of the time it is saying false. Also most of the collisions occur on the left side but not the right? This has me baffled. If anyone can give me some advice on how to fix this I would greatly appreciate it!

    class rabBot extends MovieClip
    {
    var rabbitSpeed
    var sx;
    var sy;
    var traceCounter;
    function onLoad(){
    rabbitSpeed = 4;
    traceCounter = 0;
    }
    public function rabBot() {
    // constructor code
    }
    function onEnterFrame(){
    findCurrentCell();
    if( Key.isDown(100))// that's numpad '4'
    {
    if(_root.GameCode.shipComponents[sx-1][sy] == 0 || _root.GameCode.shipComponents[sx-1][sy] == 611 || this.hitTest(_root.GameCode.shipImage[sx-1][sy]) == false)
    {
    _x -= rabbitSpeed;
    }
    _xscale = 100;
    }
    if( Key.isDown(102))// that's numpad '6'
    {
    _x += rabbitSpeed;
    _xscale = -100;
    }
    if( Key.isDown(98))// that's numpad '2'
    {
    _y += rabbitSpeed;
    }
    if( Key.isDown(104))// that's numpad '8'
    {
    _y -= rabbitSpeed;
    }
    }
    function findCurrentCell()
    {

    sx = Math.round((_x -_root.shipGrid1._x +(_root.shipGrid1._width/(294/130)))/(_root.shipGrid1._width/14.75));
    sy = Math.round((_y - _root.shipGrid1._y +(_root.shipGrid1._height/(134.587/50)))/(_root.shipGrid1._height/6.7025));

    traceCounter ++;
    if(traceCounter > 48)
    {
    traceCounter = 0;
    trace("SX: " + sx + " SY: " + sy + " Component to left = " + _root.GameCode.shipComponents[sx-1][sy] + " Hit test: " + this.hitTest(_root.GameCode.shipImage[sx-1][sy]));
    }
    }

    }
    shipComponents = new Array(new Array(1,1,1,1,1,1,511,1,1,1,1,1,1),
    new Array(411,412,0,0,611,0,512,0,611,0,0,-301,-302),
    new Array(413,414,1,-2,611,1,513,1,611,-1,1,1,1),
    new Array(2,0,0,0,611,0,0,0,611,0,0,711,712),
    new Array(1,1,1,1,1,1,1,1,1,1,1,1,1));

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    PHP Code:
    class RabBot extends MovieClip{
        private var 
    _rabbitSpeed:Number;
        private var 
    _sx:Number;
        private var 
    _sy:Number;
        private var 
    _shipCell:String;
        
        public function 
    RabBot(){
            
    init_rabbit();
        }
        private function 
    init_rabbit(){
            
    _rabbitSpeed 4;
        }
        public function 
    get rabbitSpeed(){
            return 
    _rabbitSpeed;
        }
        public function 
    set rabbitSpeed(setSpeed){
            
    _rabbitSpeed setSpeed;
        }
        public function 
    moveRabbit(moveTo_x,moveTo_y,hit){
            if(!
    hit){
                
            }
            
    _sx=moveTo_x;
            
    _sy=moveTo_y;
            
    _shipCell=_sx+":"+_sy;
            
            
    this._x=_sx;
            
    this._y=_sy;
        }

    Usage

    PHP Code:
    var rabbot attachMovie("RabBot""rabbot"0);
    var 
    20;
    var 
    20;
    this.onEnterFrame = function() {
        
    callRabit();
    };
    function 
    callRabit() {
        
    x++;
        
    y++;
        
    rabbot.moveRabbit(x,y,true);

    You can post a sample project to test on my environment where I'm using CS3.


    arkitx

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    I'm sorry, I'm still new to flash programming. What exactly did you change? I don't quite understand how this would help. Also I'm not sure what you mean by testing on your environment. What does that mean and how would it help???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center