A Flash Developer Resource Site

Page 3 of 3 FirstFirst 123
Results 41 to 53 of 53

Thread: Saving a game

  1. #41
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    should the line _root.Bullet = _root.Shot - 1, be _root.Bullet = _root.Bullet - 1? Otherwise the Bullet variable will increase instead of decrease

    code:

    var mousechecker = new Object();
    mousechecker.onMouseDown = function() {
    _root.Bullet--; // shorthand for _root.Bullet = _root.Bullet - 1
    _root.Shot++;
    _root.Pistol.play();
    if (_root.Bullet == 0) {
    delete mousechecker.onMouseDown;
    }
    };
    Mouse.addListener(mousechecker);


  2. #42
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    ohh now i get it.... heh i think i could get that stuck to my head.... ok then how can we add it by 2? do we go by

    _root.Shot+++?

  3. #43
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    to add more than one to a value you can use,

    myVar = 5; // create myVar
    myVar += 2; // myVar was 5 now is 7
    myVar += 10 // myVar was 7 now is 17

    etc, subtraction is similar,

    myVar -= 10; // myVar was 17 now is 7

    and so on.

  4. #44
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    oh so we put the sign on the front except on the back

    MyVar += 2; //add 2 to MyVar
    MyVar -= 2; //subtract 2 to Myvar

    crazy me i always do it like this

    MyVar = MyVar-2
    OR
    MyVar =-2

    ok so the "if" part moves down where it delete the mouselisten actions right?

  5. #45
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    MyVar = MyVar - 2;

    and

    MyVar -= 2;

    both do the same thing, the 2nd version just requires a little less typing, whereas

    MyVar =-2

    is totally different, this just gives MyVar the value -2

    the if section of that code just removes the onMouseDown method of the mousechecker object (when the bullets run out) doing this stops all the actions that were contained in the method (reducing the bullet count etc) from happening when the mouse is pressed.

  6. #46
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    what about

    MyVar3 = MyVar1 + MyVar2

    The resault i get is 51
    (By the way)
    MyVar 3 = ?
    MyVar 1 = 5
    MyVar 2 = 1

  7. #47
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Where are the values for MyVar1 and MyVar2 coming from? If either of them are supplied through an input textfield they will be treated as text and instead of adding the values the + operator will be used to concatenate (join) them together as a string,

    equally if you set the values by hand as somthing like,

    MyVar1 = "5";
    MyVar2 = 1;
    MyVar3 = MyVar1 + MyVar2; // the result is 51

    or,

    MyVar1 = 5;
    MyVar2 = "1";
    MyVar3 = MyVar1 + MyVar2; // the result is 51

    or,

    MyVar1 = "5";
    MyVar2 = "1";
    MyVar3 = MyVar1 + MyVar2; // the result is 51

    because each time one or more of the values being added together is a string, to get the expected result you need to make sure the values are set as numbers,

    MyVar1 = 5;
    MyVar2 = 1;
    MyVar3 = MyVar1 + MyVar2; // the result is 6

    if the values came from input textfields (which menas they are strings regradless of what was entered) then you need to convert them into numbers before adding them,

    MyVar3 = Number(MyVar1) + Number(MyVar2);

  8. #48
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    i'm working on a RPG game... it's like when you purchase your armor your status increases by an ammount

    (Hero Property)
    Base Strength (Str): 5
    Current Strength (StrC): 5

    (as for the armor property)
    Armor Strength Addition (ArmorS): +1

    this the trigger i have

    StrC = Str + ArmorS
    but then it didn't work.... oh an can you exactly explain about _root? i don't get it. (not really tho)

    (edit)
    i forgot to mention........ how do we add Variables like

    Str1 = Str2 + ArmorS? (well i try that i get "(nothing)" if i add roots to Str1 i get 0 if i add root to all of them i get (Str2)(ArmorS) together.
    Last edited by AznStyolz; 10-29-2003 at 08:29 PM.

  9. #49
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    _root is a reference to the main timeline of the current document level. unless the movie has been loaded into a movie clip using the loadMovie action this will target the main timeline of the movie that contains the action that uses _root,

    eg

    _root.gotoAndPlay(10);

    sends the main timeline to play frame 10,

    _root.myVar = 1;

    sets a variable named myVar on the main timeline to be equal to 1.

    _root.myClip.stop();

    stops a movie clip named myClip placed on the main timeline. since _root always targets the main timeline (provided the movie wasn't loaded into a movie clip first) these actions can be placed in any timeline of your movie and they will all still work in the same way.

    When you are trying to add up the variables are they all defined in the same timeline or in different places?

  10. #50
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    different Frames

  11. #51
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    would you be able to post your fla file (or the section of it that is causing problems) ?

  12. #52
    Member
    Join Date
    Sep 2003
    Location
    CA / Long Beach
    Posts
    45
    the thing is connected to each other.
    Scene 2 sets the status.
    scene 4 shows the status... but i'll try.... i'm going with scene for now... untill i learn more about actions i'll make everything through using Frames. Do you have A E-maill address that i can send it to you at?

  13. #53

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