Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 Viewsyea that makes sense but how would I include say a movie clip to happen after it enters
you could addChild them to the game. Did you addChild the container of your game to the stage or are you working with frames?
At 2/2/14 12:55 AM, Etherblood wrote: This should do the trick:
if (aiNumber <= 7)
{
aiAttack();
}
else if (aiNumber <= 9)
{
aiMagic();
}
else
{
aiHeal();
}
Unfortunately that didn't work for the aiMagic because it would still cast magic if it was <= 9 but attack is <= 7. It works for attack and heal but I need magic to be 8 or 9 only. If it is <= 9 then odds are it will also be <= 7 which is what attack is.
My code currently makes a random number between 1-3 and then based off which number it is the AI in my game executes one of three choices: attack, magic attack, heal.
function aiChoices():void
{
aiNumber = Math.ceil(Math.random() * 3);
if (aiNumber == 1)
{
aiAttack();
}
if (aiNumber == 2)
{
aiMagic();
}
if (aiNumber == 3)
{
aiHeal();
}
}
The code works perfectly. But I realized that I wanted to make it so that more often the AI attacks, less often uses magic, and even less often heals. To do this I changed my math.random to:
aiNumber = Math.ceil(Math.random() * 10);
I want to make him attack if the number is 1 - 7, magic if 8 - 9, and heal if 10. I don't know how to check if it is within a certain range. How would I change this:
if (aiNumber == 1)
{
aiAttack();
}
To check if aiNumber is between 1 and 7?
Didn't know the exact words to Google and thus I just ended up getting webpages/forums of people not know how to generate a random number with math.random.
Thanks in advance guys.
At 2/1/14 09:19 PM, MSGhero wrote:At 2/1/14 09:10 PM, Hero101 wrote: I know this is probably not the most ideal way of doing this with Timers. But for now with this tiny game it works.milchreis' suggestion about onComplete would probably solve your problems.
vt = TweenLite.to(thing, 1, { y:255, onComplete:onceTheTweenIsOver } );
.....
function onceTheTweenIsOver():void {
display text
reset tween or whatever
Thanks again I will look into that. If I can get that to work it will make my code more compact and simpler than the way I am going about it.
Can you post actual code? You don't have to show the contents, just the function headers and all the class stuff. Wouldn't checkPlayerPosition be inside the enterframe handler? I can't tell if you're calling the functions or defining them based on your comments.
Based on your error 1069 or whatever from a few threads ago, it seems like your timer or tweenlite callback is happening before you're ready to handle it.
Ok sorry to all those who replied I guess I wasn't clear enough with my question and bad pseudo code. I do understand that you can't (as far as I know) put functions inside of functions in the way that kkots was demonstrating. I wasn't doing that. I was doing:
function hungerLevel():void
{
if (hungry)
{
getPizza(); // This is what i meant. Firing a call to another function from within a function.
}
}
At MSGhero's request here is my code. I stripped out all the other non-essential code as my game is at 1000 lines long and don't want to blow up this forum post with it.
package
{
public class Game_Manager extends MovieClip
{
var vHealTimer:Timer = new Timer (1000, 1);
//AI Timers
var aiAttackTimer:Timer = new Timer (1000, 1);
var aiDeathTimer:Timer = new Timer (1000, 1);
//Declare text container
var damageDisplay2:DamageDisplay2;
//Store number for heal amount
var vHealAmount:uint;
public function Game_Manager()
{
//Add and position text container
damageDisplay2 = new DamageDisplay2();
gameCon.addChild(damageDisplay2);
damageDisplay2.x = 425;
damageDisplay2.y = 270;
var vTween:TweenLite = new TweenLite(damageDisplay2, 1, {y:255});
vTween.pause();
vHealTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onVHealTime);
function onVHealTime(event:TimerEvent):void
{
playerOneState(); // This just makes it player one's turn which I omitted the code for in this example
damageDisplay2.hitDisplay2.text = ""; //Erases text
trace ("vHealTimeUp");
}
//When it is the AI turn this function fires
function aiChoices():void
{
aiNumber = 1);
if (aiNumber == 1)
{
aiHeal();
}
}
function aiHeal():void
{
{
vHealAmount = Math.round(Math.random() * 10) + 5
gameCon.vHealth.text = "" + (villianHealth += vHealAmount);
gameCon.vHeal.text = "" + (villianHealRemaining -= 1);
damageDisplay2.hitDisplay2.textColor = 0x0000FF;
damageDisplay2.hitDisplay2.text = "+" + vHealAmount; //Displays heal amount
vTween.restart(); //starts tween for text
vHealTimer.start(); //starts timer. When it finishes it runs function onVHealTime above
trace ("aiHeal");
}
}
The trouble I was having was that at random when it was the AI's turn and he would heal himself this part of code:
damageDisplay2.hitDisplay2.text = "+" + vHealAmount; //Displays heal amount
Wouldn't always display the heal amount.
MSGhero suggest that " it seems like your timer or tweenlite callback is happening before you're ready to handle it." and I believe he is right. That's because I was able to fix it by taking this:
function aiChoices():void
{
aiNumber = 1);
if (aiNumber == 1)
{
aiHeal();
}
}
and changing it to this:
function aiChoices():void
{
aiNumber = 1);
if (aiNumber == 1)
{
aiHealTimer.start(); //delay the heal function for 1 second
//instead of it firing right away at start of AI turn
}
}
//And have that timer call the aiHeal function
function onAiTime(event:TimerEvent):void
{
aiHeal();
}
I know this is probably not the most ideal way of doing this with Timers. But for now with this tiny game it works.
Can you post actual code? You don't have to show the contents, just the function headers and all the class stuff. Wouldn't checkPlayerPosition be inside the enterframe handler? I can't tell if you're calling the functions or defining them based on your comments.
Based on your error 1069 or whatever from a few threads ago, it seems like your timer or tweenlite callback is happening before you're ready to handle it.
Ok I will have to do it tomorrow. Hopefully you can reply tomorrow.
Thank you for your help MSGhero
No, function calls go in the order you call them. I feel like your pseudo code doesn't accurately describe what you're trying to ask; "enterframe function down here" doesn't make sense within the GameManager constructor.
How so? If I only have on AS file that I run through the doc class in Flash IDE wouldn't I have my enterframe function inside the GameManager constructor with the rest of my code for the game?
If your functions are being called out of order, you might want to add traces or breakpoints to see what's the issue. If it's conflicting things within different events,
Yeah I've been running traces all day. I'll figure it out eventually...
keep in mind enterframe gets run before click events.
That is true. However, what if it's not a click event say it was a function called at the start of the swf like in this pseudo code
package
{
public class gameManager extends MovieClip
{
public function Game_Manager()
{
//Call a function
checkPlayerPosition(); //Just made up an example of some function ran at start of program
//Enter Frame function down here
//checkPlayerPosition function down here
}
}
}
Would the Enter Frame still fire before that first function call at top of code?
What I mean by the title is this: Say I have a single AS file that my game runs through. Like say I have a function in the middle of my code call a function at the bottom that then sets a value in another function at top. Before you tear me apart for why would I do something through so many functions here is some pseudo code:
//Listeners near top
//Listener of player attacking
playerAttack.addEventListener(MouseEvent.CLICK, onPlayerAttack);
//Timer listener that fires after player attack timer countdowns
playerAttackTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onPlayerAttackTime);
//Function in middle of as file
//Function is waiting for timer from function near bottom of as file to start and complete
function onPlayerAttackTime(event:TimerEvent):void
{
//execute some code
//remove text from dynamic text field
}
//Function near bottom of as file past other functions
function onPlayerAttack(e:MouseEvent):void
{
//execute some code
// add text to dynamic text field
playerAttackTimer.start();
}
So in the code above I have code that is triggered near the top of the as file that then runs code down near the bottom of the as file which then calls code somewhere in the middle of the as file. Now to be clear this is just pseudo code.
What I'm wanting to know is if doing it this way could cause any delay in the code being fired at any point from start to end. I'm also asking because I realized I did this an aspect in my AS file for my game and I'm having trouble with displaying the text. Sometimes it displays and sometimes it doesn't. That's why I included in the comments of the pseudo code where I would be using code for displaying or removing text.
Despite my current predicament I was ultimately curious if the order of functions matter in your AS file? Especially if they are calling other functions up or down the order in the AS file.
Hopefully my question is clear enough...
Thanks in advance guys.
At 1/31/14 05:06 AM, DIWAKAR wrote: I found that stop(); comaand is not working online but was working offline
Please help me solve the problem
Post some code dude so people here can help you
At 1/30/14 11:57 PM, MSGhero wrote:At 1/30/14 11:52 PM, Hero101 wrote: So really my question, as stated in first post, is how bad are these output errors? If they don't effect the game (as far as I'm aware of) should I still worry?It could be an issue eventually. You should fix it, fix all errors.
Damn... Ok I'll look into it. I just know that the error shouldn't be popping up with the code I've written. I must be overlooking something small. I'll figure it out. Thanks MSGhero.
I got this error: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-473()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
Ok ignore my explanation of the game. After even more research I realize I am getting this error because I am trying to remove a DisplayObject with removeChild that apparently is not a child of the DisplayObjectContainer this code is executed from. I checked the code and as far as I'm concerned I shouldn't be getting this output error.
So really my question, as stated in first post, is how bad are these output errors? If they don't effect the game (as far as I'm aware of) should I still worry?
Forgive me if this is a dumb question with an obvious answer. I'm still learning.
Thanks in advance guys.
How bad is it if you get an error in the Output panel but than game functions just fine???
I got this error: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-473()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
In my game of player vs player turn-based RPG like battle I have a timer that starts after someone attacks. After 1 second the timer switches it to the other players turn. I recently added a single player mode (still working on figuring out code). I figured out how to make the AI attack by have the AI call an attack function which is also the same function that player 2 would use in 2 player mode.
The code works and the game is fine but this error shoots up in output panel. Should I try to figure it what is causing it? Or if the game is fine (and it's a simple, small game) just let it be.
You can do conditional compilation so you can "have a copy" of both swfs without changing the code at all. Stick the api stuff in a CONFIG::toggle and it'll only get compiled when you have that compiler constant set to true.
Whoa very interesting. I didn't know Flash could do that. I'll look into it. Thank you :)
So I don't need to bother removing the code should I upload it elsewhere?
So I'm a few weeks out from finishing my first game. I already put newgrounds API into it because I wanted to add medals to it just for fun. Now I doubt I will upload it to any other website other than newgrounds, but in the event that I do I was wondering: Would I have make a new swf where I remove the coding that unlocks the medals? Or will that coding only fire if it is uploaded here on newgrounds?
I live in Portland, Oregon and games and movies have been taking a really long time to load for me :/ Oh well, it keeps me more focused on programming my game rather than finding distractions in other people's work :P
There's no need for a Timer or delay, just set the callback for the completion of the tween:
http://www.greensock.com/as/docs/tween/com/greensock/TweenLite.html
says:
onComplete : Function A function that should be called when the tween has finished
Thanks for the tip milchreis. I'll have to give it a try.
I've been learning AS3 and definitely still consider myself a beginner. After learning enough code through a book I bought, online tutorials, and with the help of you guys here on the forums I have started working on my first real game. I've been at it a few weeks now and it feels like a 2 step forward 1 step back process. What I mean by that is every time I add a new feature to the game there are bugs that arise from it. These are not game breaking bugs: When I test the game it loads with no errors, the output panel is clean, and when I debug the game it comes up clean. I guess it's more like loopholes in my coding more than bugs. For example, in my current game it's a simple turn-based RPG battle like game where you take turns attacking, casting magic, or healing as you try to defeat your opponent. Anyways, I found that when it wasn't the player's turn he could still attack (whether it be because event listeners for his turn were still active or I didn't make a boolean for when his turn was active or ect.). You get the idea. It ruins the gameplay but it wasn't a game breaking bug (if you get what I mean when I say that).
Sooooo..... My question is do you programmers fix all these bugs and/or loopholes in your coding when building a game? Or do you guys make note of it, like write it down on a list of things to fix later, and just continue to program the rest of the game? Is this a matter of personal preference among programmers? Or is it proper programming etiquette to squash these bugs/loopholes the moment you find them?
I personally fix them as soon as I encounter them. I do this because as I stated at the start of this post I am a beginner and so I find that working to correct the bugs/loopholes better helps me understand the code and learn how I could have done things more efficiently.
Flash forumns are generally for asking questions and not really for trying to promote your flash movie/get views/ratings/comments/whatever you were trying to accomplish by posting it here.
Just sayin'.
Where is TweenLite documentation? It should describe all the methods and when they need to be ran.
See what happened? You're just blindly guessing how to make it work.
Actually to be fair I did read the TweenLite documentation.... I just had some trouble understanding at the time of my post. I get it now.
MSGhero: I will have to look into that method you suggested. I used a timer for this case because I had other things that needed to happen after a 1 second timer finished so I just dropped the tween in their. Good to know about this method though for future use.
At 1/28/14 09:29 PM, Hero101 wrote: Well I figured it out...
I had to change the vTween in the attack function and timer function to vTween.restart();
Actually in case anyone was going to say it.... I didn't need to have the vTween.restart(); in the timer function. Just deleted it and still works fine.
Well I figured it out...
I had to change the vTween in the attack function and timer function to vTween.restart();
you know just above the code where I initialize TweenLite I have this
damageDisplay2 = new DamageDisplay2();
damageDisplay2.x = 425;
damageDisplay2.y = 270;
Would one way to make this work be to just use
damageDisplay2.x = 425;
damageDisplay2.y = 270;
after addChild the damage display container each time?
So I started working with TweenLite today and I'm starting to get the hang of it. I'm using it for my simple game where players take turns attacking one another in turn-based RPG style combat. When one of the players takes damage I addChild the container to display the damage they received. Then after a 1 second timer I removeChild that container. I am using TweenLite to tween the display container after I addChild it (just moving it up 15 pixels for effect).
Everything works except that the next time that player takes damage the tween doesn't work. Instead the damage is displayed standing still where the last tween ended. Is there a way to like reset the tween in the same function where I removeChild the display container?
Here's the code:
//area where you initialize variables...
var vTween:TweenLite = new TweenLite(damageDisplay2, 1, {y:255});
//If I don't pause it then I end up with the predicament I'm in from the get go...
vTween.pause();
//function for when player 1 attacks
function playerOneAttack():void
{
gameCon.gotoAndStop(1);
villianDamage = uint(gameCon.vHealth.text);
hAttackDamage = Math.ceil(Math.random() * 10)
gameCon.vHealth.text = "" + (villianHealth -= hAttackDamage);
gameCon.hero.gotoAndPlay(1);
//Here is the code that I'm using to add the damage display container
gameCon.addChild(damageDisplay2);
damageDisplay2.hitDisplay2.textColor = 0xFF0000;
damageDisplay2.hitDisplay2.text = "-" + hAttackDamage;
//Play the tween and it works...
vTween.play();
//1 second timer
hAttackTimer.start();
//Function run after 1 second timer runs
function onHAttackTime(event:TimerEvent):void
{
playerTwoState();
//Remove the damage display container...
gameCon.removeChild(damageDisplay2);
//Here is where I tried the many different controls for tweens but none of them worked...
vTween.invalidate();
trace("time up 2");
}
Hopefully I made my question clear. I want to reset the tween back to it's start position in the timer class so that the next time I addChild the damage display container it won't start where the previous tween ended.
Thanks for the tip and thanks for the help :)
You might have to addChild the playButton after it's done loading or something dumb like that.
Oh ok. If that's the case would this work:
removeChild(flashAd);
Also if I'm gonna have to addChild the playButton then couldn't I just addChild the API preloader component instead of the playButton. That way I could make sure game is fully loaded before removing ad. Or does FlashAd already have a preloader in it???
So I've been messing with newgrounds API. Finally got it to work in Flash. I am importing and addChild the flashAd to the stage using AS3.
I want to addChild my game after the player clicks the play button on the ad. I know how to do this with like:
flashAd.playButton.addEventlistener(MouseEvent.CLICK, startGame);
But when I test the swf it just has a placeholder for the ad (for obvious reasons) and thus the play button never loads. I opened up the flash component in Flash and see that the play button resting there on the second frame of the Flash Ad component.
I tried turning the debug mode to release mode with code I found in the API wiki
import com.newgrounds.API;
API.debugMode = API.RELEASE_MODE; // turn off debugging
hoping I could bypass it stopping on the ad placeholder but that didn't work.
Is the only way to truely test it is to upload it to the dumping grounds?
I did notice that in the wiki it says "You can also use the components in ActionScript if you are using a code-based workflow such as FlashDevelop or Flash Builder." I'm just using Flash Pro and coding in a single Class.as file that I use in the main doc.
With what was just mentioned it also said in wiki to:
import com.newgrounds.components.*;
//Followed by code for medals, popups, etc...
Do I need to do the import code at the top of my class?
does your project actually contain the classes for the API?
Also FlashAd may not be the correct class, I was guessing. Check the wiki to see which ones you need.
Thank you for the reply again. I have been looking at the wiki to try and figure this out.
I know it's probably a dumb question but how would I check if my project contains the classes for API?
Because right now it's connected when I run it so it works so far as is. I just can't seem to control it with AS3 which
I know you can so I must be doing something wrong...