157 Forum Posts by "Etherblood"
At 10/29/14 12:05 AM, Rovertarthead wrote: Ok and a few lines of what are enough?
A few lines of what is traced into the output.
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentTime:Number = today.getTime();
var targetDate:Date = new Date(2014,9,31);
var targetTime:Number = targetDate.getTime();
var timeLeft:Number = targetTime - currentTime;
if(timeLeft > 0 ){
var sec:Number = Math.floor(timeLeft/1000);
var min:Number = Math.floor(sec/60);
var hours:Number = Math.floor(min/60);
var days:Number = Math.floor(hours/24);
trace(sec);//<--trace for testing
sec %= 60;
min %= 60;
hours %= 24;
trace(sec);//<--trace for testing
var counter:String = String(days) + ":";
if(hours < 10) counter += "0";
counter += String(hours) + ":";
if(min < 10) counter += "0";
counter += String(min) + ":";
if(sec < 10) counter += "0";
counter += String(sec);
time_txt.text = counter;
}else{
trace("TIME'S UP");
var newTime:String = "00:00:00:00";
time_txt.text = newTime;
delete (this.onEnterFrame);
}
}
At 10/28/14 11:45 PM, Rovertarthead wrote: Ok will do and thanks for all your help sorry I wasn't getting it right I was just having a hard time before. Also I just tried it and its still the same thing. Also now says this on the Compiler Errors
Ok, apparently as2 doesn't know int, try:
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentTime:Number = today.getTime();
var targetDate:Date = new Date(2014,9,31);
var targetTime:Number = targetDate.getTime();
var timeLeft:Number = targetTime - currentTime;
if(timeLeft > 0 ){
var sec:Number = Math.floor(timeLeft/1000);
var min:Number = Math.floor(sec/60);
var hours:Number = Math.floor(min/60);
var days:Number = Math.floor(hours/24);
trace(sec);//<--trace for testing
sec %= 60;
min %= 60;
hours %= 24;
trace(sec);//<--trace for testing
var counter:String = days + ":";
if(hours < 10) counter += "0";
counter += hours + ":";
if(min < 10) counter += "0";
counter += min + ":";
if(sec < 10) counter += "0";
counter += sec;
time_txt.text = counter;
}else{
trace("TIME'S UP");
var newTime:String = "00:00:00:00";
time_txt.text = newTime;
delete (this.onEnterFrame);
}
}
Please tell me again what the output looks like when executing this. (a few lines are enough)
At 10/28/14 11:03 PM, Rovertarthead wrote: And it still speeds thro my numbers like nuts. Should I change the numbers to my own numbers? And is this were i put the action script?
Very good, the output is exactly what I expected it to be, try this script:
(replace the current one with this)
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentTime = today.getTime();
var targetDate:Date = new Date(2014,9,31);
var targetTime = targetDate.getTime();
var timeLeft = targetTime - currentTime;
if(timeLeft > 0 ){
var sec:int = timeLeft/1000;
var min:int = sec/60;
var hours:int = min/60;
var days:int = hours/24;
sec %= 60;
min %= 60;
hours %= 24;
var counter:String = days + ":";
if(hours < 10) counter += "0";
counter += hours + ":";
if(min < 10) counter += "0";
counter += min + ":";
if(sec < 10) counter += "0";
counter += sec;
time_txt.text = counter;
}else{
trace("TIME'S UP");
var newTime:String = "00:00:00:00";
time_txt.text = newTime;
delete (this.onEnterFrame);
}
}
I hope It'll work, It still does the same, but I no longer use the same var for text and numbers.
(again, I never used as2 and the stuff i wrote above is untested, so there are no guarantees)
If it doesn't work we'll just continue to test it, post any new errors pls.
If it does I'll explain how to make a 2:30 timer from here.
At 10/28/14 10:53 PM, Rovertarthead wrote: Oh you mean like this right here?
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date(2016,7,25);
var targetTime = targetDate.getTime();
var timeLeft = targetTime - currentTime;
trace(timeLeft );// <--insert this trace
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hours = Math.floor(min/60);
var days = Math.floor(hours/24);
sec = String(sec % 60);
if(sec.length < 2){
sec = "0" + sec;
}
min = String(min % 60);
if(min.length < 2){
min = "0" + min;
}
hours = String(hours % 24);
if(hours.length < 2){
hours = "0" + hours;
}
days = String(days);
if(timeLeft > 0 ){
var counter:String = days + ":" + hours + ":" + min + ":" + sec;
time_txt.text = counter;
}else{
trace("TIME'S UP");
var newTime:String = "00:00:00:00";
time_txt.text = newTime;
delete (this.onEnterFrame);
}
}
It should look like this afterwards.
At 10/28/14 10:49 PM, Rovertarthead wrote: Ok sure thing and where do i put this on the top or bottom of the action script that i have on now? Or just replace the whole script with this one?
The line above and below the trace are already in your script, search for them and place the trace inbetween.
At 10/28/14 10:29 PM, Rovertarthead wrote: Oh ok yea it was and yes it is at all 00000 and take a look at the upload i just did heres what it looks like right now. > http://www.newgrounds.com/portal/view/646656
Hmm... We'll just step through it and see where it goes wrong.
var timeLeft = targetTime - currentTime;
trace(timeLeft );// <--insert this trace
var sec = Math.floor(timeLeft/1000);
Try putting in this trace and see what the output says.
It represents your countdown in milliseconds, if it works as it's supposed to, the trace output should show a really large number which is decreasing 1000 units per second.
I suspect the string conversion stuff afterwards to cause the issues if this works.
At 10/28/14 09:30 PM, Rovertarthead wrote: Ok no I tried another code so I erased that one and am just going to go by yours. So ok I put this one back in you just gave me and it is working.. But not quiet the numbers are speeding tho randomly now in the SWF export file.
This is not my code, this is the code you posted in your last thread.
At least we're making progress now.
I assume the number of digits for each part is correct? ("00:00:00:00")
I can't find an error in the calculations, but i'll check again.
The mouse event error is unrelated to this problem and likely somewhere else in your file.
At 10/28/14 09:20 PM, Rovertarthead wrote: Server error! Unable to obtain date from server
Error opening URL 'file:////Volumes/Macintosh%20HD/Users/keithendow/Desktop/Trevors%20MacBook%20Pro%20Desktop/Trevors%20iMac%20Desktop/Trevors%20folder/Trevors%20Artwork/Animation/Haloween%20window%20animations/Halloween%20Projector%20animations%20Completed/gettime.php'
are you still using the code from last thread?
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date(2016,7,25);
var targetTime = targetDate.getTime();
var timeLeft = targetTime - currentTime;
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hours = Math.floor(min/60);
var days = Math.floor(hours/24);
sec = String(sec % 60);
if(sec.length < 2){
sec = "0" + sec;
}
min = String(min % 60);
if(min.length < 2){
min = "0" + min;
}
hours = String(hours % 24);
if(hours.length < 2){
hours = "0" + hours;
}
days = String(days);
if(timeLeft > 0 ){
var counter:String = days + ":" + hours + ":" + min + ":" + sec;
time_txt.text = counter;
}else{
trace("TIME'S UP");
var newTime:String = "00:00:00:00";
time_txt.text = newTime;
delete (this.onEnterFrame);
}
}
if not, what does your current code look like?
At 10/28/14 08:28 PM, Rovertarthead wrote: and I do get an error on the output I will send you a screenshot.also there's one on compiler Errors.
No need to screen the error(s), you can just copy it as text, what does it say?
At 10/28/14 05:19 AM, Rovertarthead wrote: Wait no i did try it. It's just not working.
What I posted was not a solution to fix your problem, it was to try finding what your problem is.
We can't help you if we don't know whats wrong, but you just keep telling us that it doesn't work.
I'll ask again, what does not work?
Do you get an error?
Is your problem to put the calculated values into a textfield or are the calculations wrong?
Or something else?
And if an answer doesn't instantly solve your problem, take your time to tell us that you tried and what exactly happened when you executed it. We can continue solving your problem from there.
At 10/28/14 02:35 AM, Rovertarthead wrote: Hi if there's any action scriptur out there I have a file I will be willing to send to you if you can help me out and fix it for me on it. I have Adobe flash CS6 file with a countdown timer in it. But I cannot get it to work right I was wondering if anybody will be willing to download the file I would be happy to send it to them if you think you can look in it and fix in the right timer countdown action script for it. Countdown to Halloween. And a two-minute in 60 seconds timer. Please anyone message me back. Thanks
I already tried to help you, but you just ignored me...
Also, this is your 3rd thread for this problem or did I miss one?
At 10/26/14 04:41 PM, coderchick94 wrote: for(var i:int = 0; i < buttonsWin.numChildren; i++){
buttonsWin.removeChild( buttonsWin.getChildAt(i) );
}
What this loop does is removing every element that has an even index from the list.
Just imagine what happens if you execute this loop step by step.
First it will remove the element at index 0 in the list.
All other elements in the list will move 1 to the left (towards 0), to fill the existing gap.
The element that was at index 1 at the beginning is now at index 0.
i is now increased by one for the next step.
By the time half the elements are removed, i will be increased by the same amount, causing the loop to end.
(because the index of the half + 1's element is higher than half the initial list size)
Usually one executes this loop backwards to remove elements:
for(var i:int = length - 1; i >= 0; i--)
remove;
This way you always remove the last element each step until it is empty.
There will be no gap which would cause the elements to move.
The while loop just works the other way around, it always removes the first element, all others will move to fill the gap and you have a new first element.
At 10/21/14 09:43 PM, Rovertarthead wrote: Here it Izzur >
Hmm, I can't find any mistake, never used AS2 though. (can you use the same var for strings and numbers?)
You might want to insert a few traces to find out what the problem is.
What is traced if you insert a trace like this?
if(timeLeft > 0 ){
var counter:String = days + ":" + hours + ":" + min + ":" + sec;
trace(counter);
time_txt.text = counter;
}
At 10/20/14 11:43 PM, Rovertarthead wrote: Here is the half of the action script i had copied the whole thing couldnt fit... onto my Flash file. Hopefully you could make it countdown to Halloween and another one for 2 min and 60 sec That would be awesome
So what exactly is your problem?
Your game show's just 0's, so is your problem that you can't get your textfields to display your calculated time?
Or is something with your time calculation wrong?
If something with your calculations is wrong, posting half of it won't help much.
At 10/14/14 08:50 AM, Glboom wrote: What I am trying to say is, do I really have to wait to get to Game design course in college to learn all the inportant and amazing skills needed to learn game development, or could I really learn many not most of the stuff right now since I have so much free time. Because I have no patience.
Learning how to make your phisics/rendering yourself takes a lot of time but is doable, just take one step at a time.
It is not neccessary though, using libraries is much easier.
I learned a lot about game programming over the years by just googling what I needed.
(stuff like 2d collision-detection/response, 3d rendering, pathfinding, chess ai etc)
You'll just have to find the pieces you need and put the pieces together yourself, college helps but is not neccessary.
And you'll need patience, making a 'complex' game without prior knowlege is not something you can do in just a few months.
I might be able to share a few very useful links depending on what you want.
At 10/13/14 01:53 PM, MintPaw wrote: The error says frame 3, line 43.
Yes, but he should somehow mark which line is line 43.
Empty lines got removed in his post (and look identical to double empty lines) due to missing code tags, I'm to lazy to count and make a good guess.
At 10/12/14 02:01 PM, CosmicBIt wrote: Every time i go to frame for i get this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at androidgame_fla::MainTimeline/checkBounds()[androidgame_fla.MainTimeline::frame3:43]
Test Movie terminated.
And I have not idea why it is doing this.
It might be helpful to tell us in which line the error happens.
Also, you wrote 4 times the same code, you should learn how to use arrays and loops, you'll need much less code for the same result.
At 10/9/14 06:02 AM, Hero101 wrote: Thank you for all your input and help. It is much appreciated.
I do hope everything is ok with your computer :/
It was just my driver being funny, all good.
Do you still need help or want more explanations for this topic?
At 10/9/14 04:21 AM, Hero101 wrote: There are 5 melee weapons that _weapon was going to keep track of and you always get them in the same order. So I was planning on making _weapon:int = 1 and then every time you get a new weapon (replaces previous weapon) I was going to just simply do _weapon++;
hmm, what you want to do is basically an array with 5 weapons in it and an index pointing to the current one?
I imagined the weapon stuff more like this (only an example):
currentWeapon = new Weapon("hammer", 27);//gives the player a hammer which deals 27 dmg
Note that the constructer arguments can be anything, maybe you just want to create the start-weapon whithout any args etc.
If you want to upgrade your weapon you could give your weapon class an upgrade function:
currentWeapon.upgrade();
Think about what you want to do with your weapon class and plan all the functions you need, think about how to implement it afterwards.
Why should I use static variables?
static variables are shared between all instances, and it makes sense for hammer to be "hammer" no matter the instance.
An example of a static variable is Math.PI, there is no need for multiple PI's so it can be made static.
There is no real need to make it static though, you could use 30 PI's (of course all with the same value), but 1 works just as well.
How to structure code is a broad topic, and there are always ways to improve...
Wow, my graphics card just died, this looks strange...
Sry, I'll keep this answer as it is, I'll write more useful stuff later.
At 10/9/14 03:46 AM, Hero101 wrote: I have one simple question though...since the only thing I will be storing in weapons class is _weapon and _damage which are both just integers - does the weapons class need to extend anything at all?
It does not need to extend anything.
I assume _weapon will save of what kind the weapon is?
If yes I would use a string over an int because "hammer" is easier to understand than "7".
(ints work fine though, so it comes down to preference)
If you want to prevent typos you should then use static constants like
static var hammer:string = "hammer";
or analog if you're using ints:
static var hammer:int = 7;
for each weapon type.
Then you could check the weapon type with:
if(_weapon == hammer) //dostuff
At 10/8/14 07:38 AM, halfblue3 wrote: never thought of that, i guess it'll be better to use those lines of code because it considers both variables. thanks
It is better to just use 1 variable instead, girlSelected will always be the opposite of boySelected, no need to use 2 variables for 1 value.
Can't help you with your problem though, sry.
At 10/6/14 06:45 PM, Hero101 wrote: Is that correct? Because with this example you posted I wouldn't need to worry about returning anything since the damage/weapon variables would be stored in the weapon class.
The damage variable in the main class is not the same var as the one in the main class, they just have the same name.
But you would then return the damage from the weapon (with the checkDamage function) and put it into your main class damage variable.
At 10/6/14 05:53 PM, Hero101 wrote: Is there a way though to pass the damage value back to my main class? Well obviously there is a way - I mean should I just use a static variable for damage? My main class is also the document class and from what I remember you can't create an instance of it in another class. So I can't go main.damage = 1 inside my weapon class to alter the damage variable back in my main class.
This link might help you:
http://www.republicofcode.com/tutorials/flash/as3functions/
(found it at google, it looks like it does the job, you might want to google 'as3 function returntype' and look for better explanations)
What you want to do might look like this:
function checkDamage(weapon:int):int //return type is int
{
if(weapon == 1) return 1;
return 0;//functions must always return a value if their return type is not void
//so we'll just return 0 for unknown weapons
}
You already used functions with :void after their declaration, meaning their return type is void, they return nothing.
You can change this to anything you want the function to return, in this case int, you would use this function like this:
if (_weapon == 1)
{
damage = checkDamage(weapon);
_zombie._hp -= damage;
}
ps: you should make a weapon class.
At 10/2/14 02:12 PM, 512Pixel wrote: I ve tried one key as collision test . I just make a boundary line on the entire stage rather than on the movieclips area.
How can change this code to get the collision detection on th edges. missing something. Ive tried a vairety of ways and had no success . If i can one side right i can add the other sides after.
if (e.keyCode == Keyboard.RIGHT){
player.x += 5
// this create a boundary line // should i use the height as well to
// get a hit test around the left edge as an example
if(player.x + Width > block.x - widthblock ){
trace("hit");
}
Sry, I don't understand what exactly your problem is. You seem to want to get your collision to work and I pretty much posted everything needed for aabb-collision.
I always have to assume what you want your code to do, answer based on that assumption and you ask the same question again afterwards. Does this mean my assumptions were wrong?
2 rectangles, I'll call them a and b, intersect if:
a.x + a.width > b.x && b.x + b.width > a.x && a.y + a.height > b.y && b.y + b.height > a.y
(note that (x, y) is the top left corner)
You might want to google 'aabb collision', there is a lot of useful stuff out there, and it helps a lot to understand the stuff you want to code.
If you intend to make Unity games C# is a good choice as starting language. No point in learning other languages just to switch over to C# when learning it isn't really any more difficult.
At 9/25/14 06:44 PM, 512Pixel wrote: // i triedthis but the code is illegal and throws an error
if(player.x + Width > block.x - widthblock and player.x + Height > block.x+ heightblock)
Again, why are you using height here? It's pretty much always a bad idea to add height to an x-coordinate.
In AS3 the keyword for and is not and, try && like this:
if(conditionA && conditionB)
I assume you want this line to look like this?
if(player.x + Width > block.x - widthblock && player.x - Width < block.x + widthblock)
This is the x-part of an aabb-intersection check,
where player.x/block.x is the rectangles center and Width/widthblock is half the width.
At 9/25/14 09:34 AM, 512Pixel wrote: i keep getting an error .
What does the error say?
if (e.keyCode == Keyboard.UP){
player.y -= 5
if(player.y - Width < block.y +heightblock){
I'm pretty sure you meant to put Height instead of Width here.
if (e.keyCode == Keyboard.LEFT){
player.x -= 5
if(player.x + Height< block.x -widthblock){
And here it's Width instead of Height
At 9/23/14 04:48 AM, uglybetty wrote: Thank you so much! I was basically looking for a more RAM/CPU efficient code. I've had problems with that before because of for, while and while do loops. Will your last code make the numbers less random than my orginal code?
If you initialize lastRandom with Math.floor(Math.random() * 3) + 1 it will have the same propabilities as your while loop, so it won't be less random.
At 9/23/14 03:35 AM, uglybetty wrote: So, do you mean like pre-genrerating a bunch of numbers instead of real-time random numbers? Will that improve performance? If so, how would I go forward with this?
I don't know if you could call it 'pre-generating' in your case it would look something like this:
(pseudocode)
elements = [1, 2, 3]//init once
random = elements[Math.floor(Math.random() * elements.length)]
elements.remove(random)
elements.add(lastRandom)//only if lastRandom is not contained
lastRandom = random
I am pretty sure that this will take more time to execute than your while loop, but we're talking about split-milliseconds here, you won't notice any difference unless you call this millions of times per seconds. (In this case the generated random values will be more of an issue)
The 2nd way I proposed would be faster (again, you won't notice a difference), it would look like this:
random = Math.floor(Math.random() * 2) + 1
if(random === lastRandom) random = 3
lastRandom = random
All 3 versions should be valid and you won't encounter performance issues with any.
Also, in your case you could just choose a random number from 1-2 and if it equals the last random number return 3 instead.

