Actionscript help for a noob?

A place for tutorials on how to get the most out of Flash

Re: Actionscript help for a noob?

Postby hat973 » Sat Jun 14, 2014 7:55 pm

to simplely put it
https://www.youtube.com/watch?v=sTDVY2xnFv8#t=171
Im fallowing this the guy uses a If or else if in his code is it posable to add a 3rd string to a else if statement
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby Terrantor!!! » Sat Jun 14, 2014 10:47 pm

hat973 Wrote:to simplely put it
https://www.youtube.com/watch?v=sTDVY2xnFv8#t=171
Im fallowing this the guy uses a If or else if in his code is it posable to add a 3rd string to a else if statement


Are you talking about testing 3 conditions? If so, then yeah you can do as many things as you want as long as you are testing the right stuff.

Code: Select All Code
if(something==true){
     doThis();
}else if(something==false){
     doThat();
}else if(something==true && somethingElse==true){
     doSomethingElse();
}else{
     doNothing();
}




I used to do this all the time, but there's an easier way and that's through switch conditionals.
Lemme know if you're interested.

As for if you're adding a variable of datatype String to the if test, You can test strings, it gets a bit tedious, though.

pretty much just put if (this=="string"){ runThisFunction()}
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby BlueLight » Sun Jun 15, 2014 2:13 am

so a if statement is a check for a boolean; this is a important thing to remember because it can not only make the ifstatment easier to writer; but also make other things easier to understand.


A "if else" statement is normally written like "else if". This is the combination of a if statement and a else statement. It runs if the statement above did not trigger, then checks if it's if statement conditional is true or their are no other else statements below it.


else statement, triggers if none of the above if statements triggered.

quick example of if, else if, and else
Code: Select All Code

if (number == 5 || number > 3 && number <4.577584833 ) {...} //if number is 5, or above 3 and below 4.577.... the run this
else if (number == 4.577584833+ 0.3){...} //if number is equal to 4.877584833, run this
else if (A != B && (A&&!B)){...} // the A is not equal to be, and B is false along with A being true. It's confusing has this is set up but trust, A must be true and B must be false to run.
else if ( someRandomFunction() ){...}
else if ( 0 != 0){...}// this will never run but if it were, 0 must not equal to 0.
else{...}//None of the above statements true.

//bad design
//These are something you should not do.
if(myBoolean){...} // okay this will run if myBoolean is true.
if(!myBoolean){...}//this is the problem here. You are going to check both if statements are true, but [u]only 1[/u] can be true. What you should be doing for the second if statement is using "else if()" or a else statements. Both would work.





Now going back to what i said about if statement checks for a boolean. A boolean is not just a variable type but a result of from a logical condition. "A && B || C && D" assuming that all those values are booleans, will return true if A and B are true or C and D are true. That's because we're checking if the logical operation are true. This is why you can do "if(A){...}" and don't have to do "if(A==true){}".


Switch statement are more efficient if their are 4 or more conditional checks. However switch statement are limited by the fact you can't do anything except check if something is equal to something else.


There is also a ternary check which is "Conditional ? result 1: result 2". Basically you give your conditional check; add a question mark after it; if the conditional is true, then result 1 happens/returns; however if conditional is false, then result 2 is used/return.

example
Code: Select All Code
A = true;
number = !A == false? 1 : -1; // if NOT A is equal to false, number is equal to 1; else is equal to -1;
number  = Math.Max(number, number>0? 20:-15); //if number is greater than 0, then Math.Max(number,20); else Math.Max(number,-15);


Now the limitation of the ternary is that your result, is only 1 statement, unlike a if else statement where you have as many as you want. You also might have to return a value depending where it is. (I do believe in some languages you have to return a value.)
The advantage of ternary is that you can do this nearly whenever you want as shown in my example code with Math.max().



I hope you liked this brief look at conditionals. I could of covered switch states more in depth because their so unique but i decided not to.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby BlueLight » Fri Jun 27, 2014 11:33 pm

Need help.

On the gnw game, we're having a problem where we can't keep the browser page from scrolling when we use the scroll wheel.

We're using as3
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby Anonymouse » Sat Jun 28, 2014 12:36 am

Edit: My way didn't work, but try this: http://www.spikything.com/blog/index.ph ... scrolling/
User avatar
Anonymouse
 
Joined: Sun Nov 24, 2013 2:47 am

Re: Actionscript help for a noob?

Postby hat973 » Wed Jul 02, 2014 8:32 am

I'm trying to figer out Time setting like Morning noon and night in a dating sim any way you guys may know this as2 if you are wondering what i'm asking iv poked around and haven't found much on the subject
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Wed Jul 02, 2014 9:20 am

hat973 Wrote:I'm trying to figer out Time setting like Morning noon and night in a dating sim any way you guys may know this as2 if you are wondering what i'm asking iv poked around and haven't found much on the subject

depends on how your games works.

For instances if you were to do the Japanese thing, then you'd split the day up into 4. So basically what you'd do is create a instance variable in your class, and each time your game increased time to the next stage; you'd increase it by one. If it got to 4 (assuming you start at 0) then you''d change it to 0 again and increase your day counter/dayOfWeek. You'll want to create a function like "addTime():void" which will have no task but to check if number is 3 or above, if true, goto 0; if not increase by one. Days themselves is the same concept except your addTime function should called something like addDay() when your time of the day reset to 0, and they method should increase your counter by 1.

This way you don't have to call all the methods everytime time increases.

If you want something like a clock with 24 hours, then i'd suggest you go with a military time design. Change your rollover point from 3 and above, to 23 and above. When printing out the time, you can just print out time+":00" assuming time is your hour or if you want AM/PM type stuff then you could do is make a method that returns a string and uses the below code.
Code: Select All Code

//Assume hour is variable telling the current hour, and minute is telling the current minute upto 59.
return((hour==0)?12 :(hour%12)+1)+":"+minute+((hour/12 ==0)?AM:PM );//debug this yourself. It's just an example and i don't know if it will work correctly.

Also, you might now want to use 0 as a starting point.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sat Jul 05, 2014 7:17 am

well blue I'm talking a bit like in the breeding game or uh that cream game where you baby sit cream the rabbit ((when you dig around to figer out something for a game you find odd and sometimes goods))
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Sat Jul 05, 2014 8:18 am

So nearly all time systems i know about use a simple concept where the increase of one number, say A will increase number B at some point which will increase C.

Every 60 seconds, B will increase 1 minute.
Every 60 minutes, C will increase 1 hour.
Every 24 hours, Days will increase 1 day.
Every 2 days, your drunk ass will get out of bed!

That right above is the basic concept of just about every clock i can imagine. Now you don't have to use those number; for instances you say a minute is 10 seconds. or 24 hours is trippleSunday.

Now how does this relate to games like breeding season? breeding season uses a minute value which increases a hour value which increases a day counter.

So we build a simple class which allows us to increase minute, hour, and day along with getters and adder to change all 3 values. You can make the hour and day adder private if you want but if you want to increase the time by 1 hour or 1 day, it seems silly to put in 60 minutes or 60*24.

so
Code: Select All Code
public function addSecond(value:Number):Number{
   _second += value;   
    if(_second> 59){
       addMinute(_second /60);
       _second= _second%60;
   }
}

public function addMinute(value:Number):Number{
   _minute+= value;   
    if(_minute> 59){
       addHour(_minute/60);
       _minute= _minute%60;
   }

}

public function addHour(value:Number):Number{
   _hour+= value;   
    if(_hour> 23){
       addDay(_hour/24);
       _hour= _hour%24;
   }

}
.............. more code..........


Can you be more clear on the question.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby hat973 » Sat Jul 05, 2014 8:52 am

BlueLight Wrote:Can you be more clear on the question.


Ill try i can link the games im talking about if that helps
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby BlueLight » Sat Jul 05, 2014 3:09 pm

I played breeding seasons.... i don't see how that changes anything. it's still the same concept.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Actionscript help for a noob?

Postby GoRepeat » Sun Jul 06, 2014 3:07 am

hat973 Wrote:I'm trying to figer out Time setting like Morning noon and night in a dating sim any way you guys may know this as2 if you are wondering what i'm asking iv poked around and haven't found much on the subject



That sort of thing is done independent of an actual clock. You just increase the value each time the player takes an action or performs some mechanic within the game. If you want them to be able to do 10 things per day, for example, you can just make a variable and +=1 it each time an event occurs, then use it to drive morning/noon/night.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Actionscript help for a noob?

Postby hat973 » Tue Jul 08, 2014 9:34 pm

one more thing cause the code i found is to complicated a plesher bar like in the meet n fuck games
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby hat973 » Mon Dec 01, 2014 8:59 am

I'm trying to fix this and everything iv try isn't working
Spoiler (click to show/hide):

Click to Play
(Javascript Required)

Alein RE game.swf [ 23.84 KiB | Viewed 3330 times ]



this is the code in it

Spoiler (click to show/hide):

Code: Select All Code
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var upPressed:Boolean = false;
var downPressed:Boolean = false;

var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;

var leftBumpPoint:Point = new Point(-30, -55);
var rightBumpPoint:Point = new Point(30, -55);
var upBumpPoint:Point = new Point(0, -120);
var downBumpPoint:Point = new Point(0, 0);

var scrollX:Number = 0;
var scrollY:Number = 0;

var xSpeed:Number = 0;
var ySpeed:Number = 0;
var maxSpeedConstant:Number = 18;
var speedConstant:int = 5;
var jumpConstant:Number = -25;
var friction:Number = 0.95;
var gravityConstant:Number = 1.5;
var animationState:String = "idle";
if(Math.abs(xSpeed)< 0.5){
   xSpeed = 0;
}
if( ( leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant * -1 ) && downBumping){
      animationState = "running";
}else if(downBumping){
   animationState = "idle";
}else{
   animationState = "jumping";
}
if(player.currentLabel != animationState){
   player.gotoAndStop(animationState);
}
if(xSpeed > maxSpeedConstant){
   xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){
   xSpeed = (maxSpeedConstant * -1);
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

stage.addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void{
   if(back.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
      leftBumping = true;
   } else {
      leftBumping = false;
   }
   
   if(back.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
      rightBumping = true;
   } else {
      rightBumping = false;
   }
   
   if(back.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
      upBumping = true;
   } else {
      upBumping = false;
   }
   
   if(back.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
      downBumping = true;
   } else {
      downBumping = false;
   }   
   

   if(leftPressed){
      xSpeed -= speedConstant;
      player.scaleX=-1;

   } else if(rightPressed){
      xSpeed += speedConstant;
      player.scaleX=1;

   }

   /*if(upPressed){
      ySpeed -= speedConstant;

   } else if(downPressed){
      ySpeed += speedConstant;

   }*/
   
   if(leftBumping){
      if(xSpeed < 0){
         xSpeed *= -0.5;
      }
   }
   
   if(rightBumping){
      if(xSpeed > 0){
         xSpeed *= -0.5;
      }
   }
   
   if(upBumping){
      if(ySpeed < 0){
         ySpeed *= -0.5;
      }
   }
   
   if(downBumping){
      if(ySpeed > 0){
         ySpeed *= 0;
      }
      if(upPressed){
         ySpeed = jumpConstant;
      }
   }else{
      ySpeed += gravityConstant;
   }
   
   xSpeed *= friction;
   ySpeed *= friction;

   scrollX -= xSpeed;
   scrollY -= ySpeed;

   back.x = scrollX;
   back.y = scrollY;
   
}

function keyDownHandler(e:KeyboardEvent):void{
   if(e.keyCode == Keyboard.LEFT){
      leftPressed = true;
   
   } else if(e.keyCode == Keyboard.RIGHT){
      rightPressed = true;
   
   } else if(e.keyCode == Keyboard.UP){
      upPressed = true;
   
   } else if(e.keyCode == Keyboard.DOWN){
      downPressed = true;
   }   
}

function keyUpHandler(e:KeyboardEvent):void{
   if(e.keyCode == Keyboard.LEFT){
      leftPressed = false;
   
   } else if(e.keyCode == Keyboard.RIGHT){
      rightPressed = false;
   
   } else if(e.keyCode == Keyboard.UP){
      upPressed = false;
   
   } else if(e.keyCode == Keyboard.DOWN){
      downPressed = false;
   }   
}


what im trying to do is make the idle animation play
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby Terrantor!!! » Tue Dec 02, 2014 1:43 am

I believe your downBumper hitTest is not being satisfied. Trace its value by inserting the function " trace(downBumping) " into your loop function. If it keeps reporting false in your console, you need to revise your conditionals in the hitTest. Try making the y value higher and I'm sure you'll get your idle and run animations working.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby hat973 » Tue Dec 02, 2014 10:05 am

Terrantor!!! Wrote:I believe your downBumper hitTest is not being satisfied. Trace its value by inserting the function " trace(downBumping) " into your loop function. If it keeps reporting false in your console, you need to revise your conditionals in the hitTest. Try making the y value higher and I'm sure you'll get your idle and run animations working.

thanks i did do a trace Down bump is working it reporting ture when i do hit up the false is also showing ill try to take my time with it ill see if i can find the condision for the jumping on i will see if i can fix the hitTest
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby Terrantor!!! » Tue Dec 02, 2014 9:29 pm

Yeah, I recommend you trace everything you can, it's a life saver!

if(player.currentLabel != animationState){
player.gotoAndStop(animationState);
}

That part needs to be in your loop statement I believe otherwise it just runs once and won't work. try putting a trace in there and see if it keeps running after an animation is supposed to change.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby hat973 » Wed Dec 03, 2014 6:20 am

Well what you sead to try last time blew up and i couldn't get it to do anything and Iv tried different forms of loop codes in that bit of code you pointed out keep getting error messages
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Actionscript help for a noob?

Postby Terrantor!!! » Wed Dec 03, 2014 8:21 am

My bad. what's the error message say? i did notice it's comparing player.currentLabel, whereas the movie clip property has currentFrameLabel. Try putting Frame in front of Label.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Actionscript help for a noob?

Postby hat973 » Wed Dec 03, 2014 9:18 am

Scene 1, Layer 'Layer 3', Frame 1, Line 37 Warning: 3553: Function value used where type Boolean was expected. Possibly the parentheses () are missing after this function reference.

that's what it sead
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

PreviousNext

Return to Tutorials



Who is online

Users browsing this forum: No registered users