A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [help] placing units on a map

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    146

    [help] placing units on a map

    I need to place units on a map. The map has areas where the units cannot go.

    Here's my code:

    Code:
    onClipEvent (mouseDown) {
    	if (setup=true) {
    
    	for (i2=0; i1 < _root.numisl; i1++;) {
    
    	if (this.hitTest(_root["land"+i1]._x,_root["land"+i1]._y)) {
    
    		_root.errmsg="Cannot Place Ships on Islands!";
    
    	} else {
    
    		stopDrag();
    
    	}
    
    	}
    }
    the setup boolean is to see if the gameplay has started or if it's still in setup mode. The numisl variable is the number of MCs where the unit cannot be placed.

    The error I get is "Scene=RandomMapGame, Layer=Boats, Frame=1: Line 17: Unexpected '}' encountered
    }"

    When I delete that '}' I get this message "Scene=RandomMapGame, Layer=Boats, Frame=1: Line 4: ')' expected
    for (i2=0; i1 < _root.numisl; i1++ {"

    Is there a way around this?

  2. #2
    Member
    Join Date
    Dec 2003
    Location
    Here.
    Posts
    48

    Re: [help] placing units on a map

    Code:
    onClipEvent (mouseDown) {
    	if (setup) {
                for (i1=0; i1 < _root.numisl; i1++) {
                    if (this.hitTest(_root["land"+i1]._x,_root["land"+i1]._y)) {
                        _root.errmsg="Cannot Place Ships on Islands!";
                    } else {
                         stopDrag();
                 }
    
    	}
    }
    try it.
    Ding.

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    well the error is gone, but the hittest isn't working. I'm gonna fool around with it for a while and try to figure it out.

    thanks a ton! didn't realise how sloppy i had written it... I must be getting tired.

    I'm doing the hittest on duplicated movieclips, hence the for loop in order to detect them all. It seems that only the first duplicate clip is being detected by the for loop.

    i can click on any of the others and the unit is placed, but when I click on the first duplicate the errmsg shows up. i'm confused!
    Last edited by Wattz; 01-19-2004 at 04:46 AM.

  4. #4
    Member
    Join Date
    Dec 2003
    Location
    Here.
    Posts
    48
    You just had a ; after i1 and you also had an i2 in there, which i thought was strange since every where else you had i1.
    Ding.

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    latest attempt...

    i tried adding another boolean in order to keep it checking for islands... i switched around the hittest to see if that was the problem...

    nothing seems to make this want to work. the problem now is that the ship will be placed anywhere you click, as if the hittest didn't exist at all.

    Code:
    onClipEvent (mouseDown) {
            i1=1;
    	if (setup=true) {
    		do {
                for (i1=1; i1 < _root.numisl; i1++) {
                    if (_root["land"+i1].hitTest(this._x,this._y)) {
                        _root.errmsg="Cannot Place Ships on Islands!";
    					this.set=false;
    				   } else {
    						_root.errmsg = "Carrier placed at " + this._x + "," + this._y;
    						stopDrag();
    						this.set=true;
     		         }
    			}
    		} while ( this.set=false );
    	}
    
    }
    please help!

    TIA.

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    code:

    onClipEvent (mouseDown) {
    setup = true;
    for (i1=0; i1<_root.numisl; i1++) {
    if (this.hitTest(_root["land"+i1]._x, _root["land"+i1]._y)) {
    setup = false;
    _root.errmsg = "Cannot Place Ships on Islands!";
    break;
    }
    }
    if (setup) {
    stopDrag ();
    _root.errmsg = "Carrier placed at "+this._x+","+this._y;
    }
    }


  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    It doesn't seem to be working.

    I've decided to change my approach. Now I'm thinking that I could declare some "safe zones" where the random islands will not be placed so that each player's ships can be placed in fair, opposite corners.

    I want 2 150x150pixel squares in the top right corner and the bottom left. I've decided that this would require the random() function to randomize a range.

    My question is now: How would I make a range? Like from 150-400 for the x value and 150-400 for the y value of the random islands.

    I'm thinking an array... I'll try it out and see how it goes.

    Thanks for all the help so far! I can't wait to show you this game!

  8. #8
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Making random values in range.
    Lets say you want them between 150 and 400.

    ran_val=random(150+(400-150));

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