A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: [Help] Stupid question really...

  1. #1
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110

    [Help] Stupid question really...

    Lo,

    I've got a stupid variables problem in an if statement;

    Basically, every time the incrementing variable, "day" gets to 7, I want the variable "week" to go up by 1 (logically... lol).
    But, it doesnt...

    function weekrise() {

    if(_root.day == 7 ){
    _root.week+=1;
    }
    }

    weekrise();

    any ideas?

  2. #2
    Member
    Join Date
    Apr 2004
    Posts
    49
    no problems there maybe if you post the rest of it... did you declare all your variables ?

  3. #3
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    I'm not sure exactly but u may want
    code:
    function weekrise() {

    if(_root.day > 6 ){
    _root.week+=1;
    _root.day=0
    }
    }

    weekrise();



    hope that helps

  4. #4
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    //Date/Week Incremention

    var dayIncrementExecutionSpeed = 1000;
    var dayIncrementSize = 1;
    var dayTriggerId = -1;


    var weekIncrementExecutionSpeed = 1000;
    var weekIncrementSize = 1;
    var weekTriggerId = -1;

    function incrementDay() {
    day +=dayIncrementSize;

    // Stop incrementing at 100
    if(day == 7) {

    // Stop the trigger
    clearInterval(stockTriggerId);
    clearInterval(creditTriggerID);
    }
    }

    //function incrementWeek() {
    // week += weekIncrementSize;
    //}

    function weekrise() {

    if(_root.day == 7 ){
    _root.week+=1;
    }
    weekrise();
    }

    function incrementCommerce() {
    commerce += commerceIncrementSize;
    if(commerce == 100) {

    // Stop the trigger
    clearInterval(commerceTriggerID);
    }
    }

    function startTriggers() {
    dayTriggerId = setInterval(incrementday, dayIncrementExecutionSpeed);
    weekTriggerId = setInterval(incrementweek, weekIncrementExecutionSpeed);

    }

    startTriggers();

    stop();

    ----

    Thats pretty much the entire coding for the incremnting of the day and week variables (note that I got rid of the incrementing week variable as it isn't based on its own increase, its based on the increase of the days). Both day and week are variables in dynamic text boxes on the main stage... See any faults?

    The extra code the previous poster suggested dint alter it either...
    Last edited by krisinyork; 06-03-2004 at 02:49 PM.

  5. #5
    Member
    Join Date
    Apr 2004
    Posts
    49
    _root.day = 0;
    _root.week = 0;
    function weekrise() {
    if (_root.day == 6) {
    _root.week += 1;
    _root.day = 0;
    }
    }
    _root.onEnterFrame = function() {
    _root.day += 1;
    weekrise();
    trace(week);
    };


    dunno what context your doing this in but function works try this on a frame script...

  6. #6
    Member
    Join Date
    Apr 2004
    Posts
    49
    didnt see.. previous post heh

  7. #7
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    lol puzzling eh?

    If anyone knows a MUCH easier way of incrementing variables, thats takes less than half the code seen above, pllllllllease let me know.

    Bloody code >:-( why won't it work.

  8. #8
    Member
    Join Date
    Apr 2004
    Posts
    49
    how is it supposed to increment if is not repeated ?

  9. #9
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    It does repeat, it repeats the function with the given guidelines by that function, i.e. speed of incremement, amount etc.

  10. #10
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182

    :)

    Hey,

    I first want to say that this post is more something for the Actionscript or Newbies forums. Don't take it personaly, but when writing a game, it's is a MUST that you understand the basics of AS.

    Now because I'm practising for writing my tutorials, I will try to explain this

    You'll first start with declaring 2 variables in frame1 of your movie:
    code:
    var day = 1; //--Assuming that 1 is monday and 7 is sunday---
    var week = 1;


    This will create the variables and give them both the value 1.

    Now we want days to pass, but we want to take care of weeks. This will be done in the folowing function:

    code:
    function addDay(amount){
    day += amount;
    while(day>7){
    week += 1;
    day -= 7;
    }
    trace("Day: "+day);
    trace("Week: "+week);
    trace("---------"
    }



    Line one: This creates a function with an argument 'amount'.
    Line two: Whatever value was added in the argument, will be added to 'day'
    Line three: This while loop, will keep looping untill day>7 returns false.
    Line for and five: When there are more then 7 days passed, it will add one to week. A week meens 7 days, so they are removed from the 'day' variable. If the value from line 3 is still true, it will repeat it again.
    Line sex to eight: This will visualize the variables once the whileloop is completed.

    Calling the function is now very easy:
    code:
    addDay(12); //--Will add 12 days---



    You can put this on a button also:
    code:
    on(release){
    addDay(3);
    }



    I hope I could explain this correct...
    Good luck,
    SaphuA

    Edit: Haha! No one replied when I was writing this post, and now look at all the posts above

  11. #11
    Member
    Join Date
    Apr 2004
    Posts
    49
    think i understand better now the prob you were having does this help ?

    var day = 0;
    var week = 0;
    // added week_count;
    var week_count = 1;
    var dayIncrementExecutionSpeed = 1000;
    var dayIncrementSize = 1;
    var dayTriggerId = -1;
    var weekIncrementExecutionSpeed = 1000;
    var weekIncrementSize = 1;
    var weekTriggerId = -1;
    function incrementDay() {
    day += dayIncrementSize;
    // Stop incrementing at 100
    if (day == 7) {
    // Stop the trigger
    clearInterval(stockTriggerId);
    clearInterval(creditTriggerID);
    }
    }
    //function incrementWeek() {
    // week += weekIncrementSize;
    //}
    function weekrise() {
    if (_root.day == 7*week_count) {
    week_count += 1;
    _root.week += 1;
    }
    }
    function incrementCommerce() {
    commerce += commerceIncrementSize;
    if (commerce == 100) {
    // Stop the trigger
    clearInterval(commerceTriggerID);
    }
    }
    function startTriggers() {
    dayTriggerId = setInterval(incrementday, dayIncrementExecutionSpeed);
    weekTriggerId = setInterval(incrementweek, weekIncrementExecutionSpeed);
    }
    _root.onEnterFrame = function() {
    incrementDay();
    weekrise();
    trace("week"+week);
    trace("day"+day);
    startTriggers();
    };

  12. #12
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Agreed with Saph, but im posting this because i went to the trouble of correcting it

    code:

    //Date/Week Incremention

    var dayIncrementExecutionSpeed = 1000;
    var dayIncrementSize = 1;
    var dayTriggerId = -1;
    var day = 1;

    var weekIncrementExecutionSpeed = 1000;
    var weekIncrementSize = 1;
    var weekTriggerId = -1;
    var week = 1;

    function incrementDay() {
    day += dayIncrementSize;

    // Stop incrementing at 100
    if(day == 7) {

    // Stop the trigger
    clearInterval(stockTriggerId);
    clearInterval(creditTriggerID);
    }
    }

    function incrementWeek() {
    if(day == 7 ){
    day = 1;
    week += 1;
    }
    }

    function incrementCommerce() {
    commerce += commerceIncrementSize;
    if(commerce == 100) {

    // Stop the trigger
    clearInterval(commerceTriggerID);
    }
    }

    function startTriggers() {
    dayTriggerId = setInterval(incrementDay, dayIncrementExecutionSpeed);
    weekTriggerId = setInterval(incrementWeek, weekIncrementExecutionSpeed);

    }

    startTriggers();

    stop();


    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  13. #13
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    ARGGHHHHHHHHH! *screams and runs*

  14. #14
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    *tiptoes back and sighs*.

    Ahhh. Heavenly Random. Where would I be without ye eh?

  15. #15
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Sometimes i think this whole forum would fall apart without me




    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  16. #16
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    Heheheh, contact me btw if you're still up for doing some of that club music.
    Ive actually got 1 more v. stupid question... lol...

    My little dudes moving about, doing his bits and bobs and - BHAM - hits a wall. I need him to go in the opposite direction whatever he was moving in (i.e. x+ -- hits a wall -- x-).

    Tried;

    this._x-=_root.con1speed;

    if(this.hitTest(_root.wwall)){

    _root.con1._x+=_root.con1speed;

    }

    But the MC only freezes on the wwall mc boundary. any ideas?
    Last edited by krisinyork; 06-03-2004 at 03:25 PM.

  17. #17
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    code:


    if(this.hitTest(_root.wwall)){

    _root.con1speed = -_root.con1speed;

    }




    OR, as a clever man once said... use tiles

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  18. #18
    Underdog to the Babes Coven
    Join Date
    May 2003
    Location
    Lincoln, England, UK
    Posts
    110
    Tiles = Evil Ta, will have a gleg n see if its working.

  19. #19
    J to the R-O-C
    Join Date
    Mar 2004
    Location
    Canada, B.C.
    Posts
    48
    Since this is kind of time/date related, how can I set a text box to always have a certain decimal amount. The clock on my game takes the hour variable, minute variable, and puts them together. But if my hour is at 04, it just converts it to 4. Anyway I can keep that 0 in there? Do I make it a string?

    Thanks
    DUN DUN... DUN!!

    Yep, bored...

  20. #20
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    code:

    //the var hour holds the current hour.
    if (hour<10) {
    hourdisplay = "0"+hour;
    } else {
    hourdisplay = hour;
    }


    and then set the textbox variable to hourdisplay

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