A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Can't add with a constantly changing variable

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    23

    Question Can't add with a constantly changing variable

    Okay, so:

    I am making a game in flash, that uses several resources to build different buildings, that help you to gain resources, etc. I'm trying to make it so that the more "_global.food" you have, the faster your resources will go up. I have it so that the variable "_global.woodBoostMeter" goes up as fast as "_global.woodBoostSpeed" and when it reaches 500, it gives you 1 wood. I want it so that "_global.woodBoostSpeed" is modified by "_global.food" divided by whatever 200 is. (So that you will get resources faster for the more food you have)

    Here's the code I'm using:

    _global.woodBoostMeter =0
    _global.woodBoostSpeed = _global.food / 200
    _global.woodBoostObtainRate =1
    onClipEvent(enterFrame){
    _global.woodBoostMeter +=_global.woodBoostSpeed
    if(_global.woodBoostMeter>=500){
    _global.woodBoostMeter=0
    _global.wood +=_global.woodObtainRate
    }
    }

    I think the problem seems to be with the "_global.woodBoostSpeed = _global.food / 200". it doesnt go up slow like it should, since "_global.food" starts out at like 200.

    Sorry if i wasn't very descriptive, lol.

    THanks!


    *** ALSO: ***
    Im using actionscript 2.0
    Last edited by Ffatty; 07-11-2010 at 11:32 PM. Reason: editted to put the code in quotes

  2. #2
    Junior Member
    Join Date
    Jul 2010
    Posts
    4
    Quote Originally Posted by Ffatty View Post
    Okay, so:

    I am making a game in flash, that uses several resources to build different buildings, that help you to gain resources, etc. I'm trying to make it so that the more "_global.food" you have, the faster your resources will go up. I have it so that the variable "_global.woodBoostMeter" goes up as fast as "_global.woodBoostSpeed" and when it reaches 500, it gives you 1 wood. I want it so that "_global.woodBoostSpeed" is modified by "_global.food" divided by whatever 200 is. (So that you will get resources faster for the more food you have)

    Here's the code I'm using:

    _global.woodBoostMeter =0
    _global.woodBoostSpeed = _global.food / 200
    _global.woodBoostObtainRate =1

    onClipEvent(enterFrame){
    _global.woodBoostMeter +=_global.woodBoostSpeed
    if(_global.woodBoostMeter>=500){
    _global.woodBoostMeter=0
    _global.wood +=_global.woodObtainRate
    }
    }


    I think the problem seems to be with the "_global.woodBoostSpeed = _global.food / 200". it doesnt go up slow like it should, since "_global.food" starts out at like 200.

    Sorry if i wasn't very descriptive, lol.

    THanks!


    *** ALSO: ***
    Im using actionscript 2.0
    I love debugging. I wouldn't trust my logic right out because I'm fairly new to AS but I have worked with Java and a game engine that's similar to flash. What I would do first is put a few trace statements in that tell you your food, woodboostspeed, and woodboostmeter variables. That way you can be watching the output to see if it adds up.

    Also, from what I gather. the food starts at 200, which when divided by 200, gives your woodboostspeed a value of 1. Have you tried putting it at a higher number, say 10000, to see if the speed of wood gain increases faster?

    Also if you could, put your code in code tags by highlighting it and clicking the CODE button (looks like #), also description is key here, you need exact numbers and as much description as will help. No one is going to tl;dr your post here

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    23
    Quote Originally Posted by Badprenup View Post
    I love debugging. I wouldn't trust my logic right out because I'm fairly new to AS but I have worked with Java and a game engine that's similar to flash. What I would do first is put a few trace statements in that tell you your food, woodboostspeed, and woodboostmeter variables. That way you can be watching the output to see if it adds up.

    Also, from what I gather. the food starts at 200, which when divided by 200, gives your woodboostspeed a value of 1. Have you tried putting it at a higher number, say 10000, to see if the speed of wood gain increases faster?

    Also if you could, put your code in code tags by highlighting it and clicking the CODE button (looks like #), also description is key here, you need exact numbers and as much description as will help. No one is going to tl;dr your post here
    I had not thought of using a trace. When i use it, it lists woodBoostSpeed as "undefined". I think it's like this because the "_global.food" variable is constantly changing. The _global.wood variable is going up like crazy when it should be going up fairy slow. After i set my _global.food to 10000 it doesn't change how fast _global.wood goes up at all.


  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    23
    okay so i was doing some more debugging to see why it isn't working.

    If i make _global.food not changing, _global.wood still goes crazy and increases way too much. dont know how much this will help, but i hope it will.

Tags for this Thread

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