Be a Supporter!

AS: Logic

  • 3,914 Views
  • 36 Replies
New Topic Respond to this Topic
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
AS: Logic 2005-10-02 13:09:17 Reply

AS: MAIN

GG Presents AS: THEORY/LOGIC

----------Introduction----------
Just knowing how to do actionscript and knowing the functions and such will not be sufficient enough to make an advanced game. Sure, you can go and make shooting games and simple enemy AI's and such, but it takes a lot more to make a game with complex AI or a complicated puzzle game. You have to be able to analyze the scripts and know what they do. Then, you have to be able to think up your own scripts.

THE GOAL OF THIS THREAD:
The goal of this thread is not to make a specific example or tutorial. It will accomplish 2 things.
1. You will be able to think like a computer in terms of processing script, which in turn will make you able to pull bugs out of script easier
2. You will be able to work backwards to make complex scripts

---------------Part 1-------------
Ok, how does the computer parse script? From top to bottom. Let's look at this simple script.

nmbr = 2
nmbr2 = nmbr*5

Now, you can just come to the conclusion that this script makes nmbr 2 = 10. Read every line of code.

make a variable named number and set its value to 2
make a variable named nmbr2 and set its value to nmbr times 5

I know this is simple stuff, but that is exactly how the computer thinks.
Consider this:

nmbr2 = nmbr*5
nmbr = 2

Now, all I did was switch the 2 lines of code around. But this time, even though the code is pretty much the same, nmbr 2 will end up as NaN. Why? Because nmbr was undefined at the time nmbr2 = nmbr*5 was read by the computer.

Here's a slightly more complicated script involving function recursion.

function freeze(){
freeze()
}

At first glance, that script might appear to be one that would freeze the computer. And yes it is, but just punching that into flash wont.

Translated into how the computer thinks:

declares a function named freeze with no parameters with the following actions
call function named freeze
end of function

That's it. ALl it does is declare a function. But, the next 4 lines of code the computer treats as ? lines of code.

function freeze(){
freeze()
}
freeze()

Into computer language:

declare function, blah blah we know this part
call freeze
end of function
// now the computer calls the function it just made
call freeze
call freeze
call freeze
call freeze
...
end function

In essence, the computer gets stuck in an endless loop.

If you have a code that's buggy, all you have to do is read the code from top to bottom. If something doesn't seem right, break it down. Why wont it work? I have some examples at the bottom of this thread for you to try.

---------------Part 2----------------
So now you know how to read script. But how can you write complex scripts? Here's some more simple problems.

You want score to increase by 1 every 10 frames. How do you do it without set interval?

Well, seems like a simple problem, but you have to realize that the computer takes orders in a basic form.
First, you have to translate the problem into computer speak.

actions to do once:
make a score variable
make a timer to keep track of when to execute the code
actions to do every frame:
add 1 to the timer
if timer is 10, indicating 10 frames, do the following actions:
add 1 to score
reset timer

Now, that might not be what you get the first time you think it through. You'll have to think how do i get an action to execute every 10 frames.

Well, every 10 frames is like a timer. So you make a count up or count down timer.
Well, once you know what you need to do, break it down to even simpler steps. After you get what I showed you above, it's time to translate into actionsctipt

onClipEvent(load){
score = 0
timer = 0
}
onClipEvent(enterFrame){
timer += 1
if(timer==10){
score += 1
timer = 0
}
}

Simple, eh?

----------------Part 3---------------
Here's some exercises for you to try, based on scripts i made in one of my puzzle games. These are much more complicated than the examples I showed above.

--EX 1--
Describe to me what this function does in STEP BY STEP form:

function ffffffffffffff(tgt) {
if (_root.meteor.enam == 1) {
tgt.xdiff = _root.meteor._x-tgt._x;
tgt.ydiff = _root.meteor._y-tgt._y;
tgt.radius = Math.sqrt(Math.pow(tgt.xdiff, 2)+Math.pow(tgt.ydiff, 2));
if (tgt.radius<=tgt._width/2+_root.meteor._wi
dth/2) {
backangle = Math.atan2(tgt._y-_root.meteor._y, tgt._x-_root.meteor._x)/(Math.PI/180)+270;
xv = _root.meteor.x_velocity;
yv = _root.meteor.y_velocity;
newspeed = Math.sqrt(Math.pow(xv, 2)+Math.pow(yv, 2));
_root.meteor.x_velocity = newspeed*Math.sin((backangle-180)*-1*(Math
.PI/180))*.90;
_root.meteor.y_velocity = newspeed*Math.cos((backangle-180)*-1*(Math
.PI/180))*.90;
_root.meteor._x = tgt._x+((tgt._width/2+_root.meteor._width/
2)*Math.sin((backangle-180)*-1*(Math.PI/18
0)));
_root.meteor._y = tgt._y+((tgt._width/2+_root.meteor._width/
2)*Math.cos((backangle-180)*-1*(Math.PI/18
0)));
if (tgt.movableing == true) {
_root.meteor.x_velocity += tgt.xA;
_root.meteor.y_velocity += tgt.yA;
}
hit.setVolume(100);
hit.setVolume(newspeed*5);
hit.start();
}
}
}

--EX 2--
Describe to me what these function do in ENGLISH:

function declareVariablesOnLoad(tgt, radius, speed) {
tgt.m_dir = 0;
tgt.m_speed = speed;
tgt.m_rot = radius;
tgt.movableing = true;
tgt.cptx = tgt._x;
tgt.cpty = tgt._y;
tgt.xA = 0;
tgt.yA = 0;
}
function xxxxxxxxxxxxxxxxx(tgt) {
tgt.m_dir += tgt.m_speed;
olxd = tgt._x;
olyd = tgt._y;
tgt._x = tgt.cptx+tgt.m_rot*Math.sin(tgt.m_dir*(Mat
h.PI/180));
tgt._y = tgt.cpty-tgt.m_rot*Math.cos(tgt.m_dir*(Mat
h.PI/180));
tgt.xA = tgt._x-olxd;
tgt.yA = tgt._y-olyd;
if (tgt.dead == true && _root.meteor.enam == 2) {
_root.meteor._x = tgt._x+((tgt._width/2+_root.meteor._width/
2)*Math.sin((tgt.backangle-180)*-1*(Math.P
I/180)));
_root.meteor._y = tgt._y+((tgt._width/2+_root.meteor._width/
2)*Math.cos((tgt.backangle-180)*-1*(Math.P
I/180)));
}
}

--EX 3--
Write a code for this:

I want a recursive exponent function that handles positive integers without using flash's built in Math functions, only *, +, -, /
Bonus: Make it able to handle negative integers too

--EX 4--
Write a code for this:

You know the ! thingy? (5! = 5*4*3*2*1, 3! = 3*2*1) Write a function for that that handles positive integers. You can only use *, +, -, /

This has been another AS thread by GG. (68 characters remaining)

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Logic 2005-10-02 13:13:23 Reply

Something a little different, nice.

Though I would say logical thinking is something you develop as you go along, not something you can read from a tutorial, though again you did post some exercises.

So nice job

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-02 13:18:36 Reply

At 10/2/05 01:13 PM, T-H wrote: Something a little different, nice.

Though I would say logical thinking is something you develop as you go along, not something you can read from a tutorial, though again you did post some exercises.

So nice job

ya, i know. But it will help a little. One of the reasons why i got so good at AS was because i'm a natural logical thinker. I might not know everything about AS, but i learn quickly and i can work around most problems with logic

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Logic 2005-10-02 13:20:03 Reply

At 10/2/05 01:18 PM, Glaiel_Gamer wrote:
ya, i know. But it will help a little. One of the reasons why i got so good at AS was because i'm a natural logical thinker. I might not know everything about AS, but i learn quickly and i can work around most problems with logic

yeah im like that too, i think thats something in common for almost every good actionscripter.

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Logic 2005-10-02 13:20:27 Reply

At 10/2/05 01:18 PM, Glaiel_Gamer wrote: ya, i know. But it will help a little. One of the reasons why i got so good at AS

lol </brag>

was because i'm a natural logical thinker. I might not know everything about AS, but i learn quickly and i can work around most problems with logic

I definately agree with that

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Logic 2005-10-02 13:23:22 Reply

Yeah this is a nice thread for some n00bs to get them thinking exactly how there code is going to be provessed and its definatly a new approach to AS:Threads. As I said in AS:Main though logic is stuff like && || etc and I thought this was going to be about something else. Other then that great job


- Matt, Rustyarcade.com

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-02 13:28:51 Reply

At 10/2/05 01:23 PM, Ninja-Chicken wrote: Yeah this is a nice thread for some n00bs to get them thinking exactly how there code is going to be provessed and its definatly a new approach to AS:Threads. As I said in AS:Main though logic is stuff like && || etc and I thought this was going to be about something else. Other then that great job

Ya, well I cant change it now

And for future refrence, && and || is syntax, not logic

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Logic 2005-10-02 13:31:45 Reply

At 10/2/05 01:28 PM, Glaiel_Gamer wrote:
And for future refrence, && and || is syntax, not logic

lol
oh glaiel you do amuse me


- Matt, Rustyarcade.com

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Logic 2005-10-02 13:36:04 Reply

At 10/2/05 01:28 PM, Glaiel_Gamer wrote: And for future refrence, && and || is syntax, not logic

Its just because the operator names are logical AND and logical OR

They are indeed syntax, just sounded like you were going to focus on them

piefi
piefi
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Logic 2005-10-02 13:45:38 Reply

thanks this helped me a lot.I have been working through AS:main and i do have a skill for thinking logically, this helped me think about scripts in english.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-02 13:47:09 Reply

An EXAMPLE OF LOGICAL THINKING!

I've been guiding frostedmuffins through locical thinking for a few days now, and look what our result is now.
http://img78.imagesh..p?image=gears8fy.swf

He's adding a little more to it now, I'll show you or he'll show you in a bit.

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Logic 2005-10-02 13:51:35 Reply

At 10/2/05 01:47 PM, Glaiel_Gamer wrote: http://img78.imagesh..p?image=gears8fy.swf

Thats just simple actionscript, you don't really need logic.. though as -KhAo- said.. most good AS'ers have good logic, which is how we figure out our problems. Nice tutorial, very different but maybe some n00bs will take advantage and try some logical thinking for a change.


Sup, bitches :)

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-02 13:55:26 Reply

At 10/2/05 01:51 PM, -liam- wrote:
At 10/2/05 01:47 PM, Glaiel_Gamer wrote: http://img78.imagesh..p?image=gears8fy.swf



Thats just simple actionscript, you don't really need logic.. though as -KhAo- said.. most good AS'ers have good logic, which is how we figure out our problems. Nice tutorial, very different but maybe some n00bs will take advantage and try some logical thinking for a change.

Well, the way we scripted it it allows us to add as many gears as we want. I taught him how to use function recursion. It's more than just simple AS.

FrostedMuffins
FrostedMuffins
  • Member since: Nov. 3, 2004
  • Offline.
Forum Stats
Supporter
Level 29
Programmer
Response to AS: Logic 2005-10-02 13:56:13 Reply

At 10/2/05 01:51 PM, -liam- wrote:
At 10/2/05 01:47 PM, Glaiel_Gamer wrote: http://img78.imagesh..p?image=gears8fy.swf



Thats just simple actionscript, you don't really need logic.. though as -KhAo- said.. most good AS'ers have good logic, which is how we figure out our problems. Nice tutorial, very different but maybe some n00bs will take advantage and try some logical thinking for a change.

Just see how it will come out, I've dealt with simple AS before, this is definately not like that stuff.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-02 15:06:09 Reply

Ya, anyone want to try my challenges?

FrostedMuffins
FrostedMuffins
  • Member since: Nov. 3, 2004
  • Offline.
Forum Stats
Supporter
Level 29
Programmer
Response to AS: Logic 2005-10-02 15:09:03 Reply

At 10/2/05 03:06 PM, Glaiel_Gamer wrote: Ya, anyone want to try my challenges?

No.... now got to get back to doing homework. And Liam, the code makes the gears, pending on how large the circle is, it imputs a certain amount of "teeth" rotates them, places them... and other stuff like that. You can put in as many as you'd like and it would all work the same.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-03 16:49:18 Reply

At 10/2/05 03:09 PM, frostedmuffins wrote:
At 10/2/05 03:06 PM, Glaiel_Gamer wrote: Ya, anyone want to try my challenges?
No.... now got to get back to doing homework.

Bad boy.... time to get the leather belt.....

And Liam, the code makes the gears, pending on how large the circle is, it imputs a certain amount of "teeth" rotates them, places them... and other stuff like that. You can put in as many as you'd like and it would all work the same.

ya, it was more compliex than it seemed

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Logic 2005-10-03 17:08:15 Reply

--EX 1--
Describe to me what this function does in STEP BY STEP form:

function ffffffffffffff(tgt) {

takes target perameter to meteor can be tested against object of choice

if (_root.meteor.enam == 1) {
tgt.xdiff = _root.meteor._x-tgt._x;
tgt.ydiff = _root.meteor._y-tgt._y;
tgt.radius = Math.sqrt(Math.pow(tgt.xdiff, 2)+Math.pow(tgt.ydiff, 2));

finds angle of meteor from target

if (tgt.radius<=tgt._width/2+_root.meteor._wi
dth/2) {

finds whether distance of the 2 circles is less than acertain value by finding whether their distance is less than or equal to the value of their 2 radiuss put together.

backangle = Math.atan2(tgt._y-_root.meteor._y, tgt._x-_root.meteor._x)/(Math.PI/180)+270;

caluculates rebound angle, equals 90 degrees to what they collided at, did you have an offset to start with like denvish did in his turning to face tut?

xv = _root.meteor.x_velocity;
yv = _root.meteor.y_velocity;
newspeed = Math.sqrt(Math.pow(xv, 2)+Math.pow(yv, 2));

pythagorian theorm, finding hypot of the triangle of old y and x verlocities

_root.meteor.x_velocity = newspeed*Math.sin((backangle-180)*-1*(Math
.PI/180))*.90;

calculates x verlocity after rebound, putting it back into ratio with _y velocity using the old hypotenuese, reduces speed to .9 of the old one?

_root.meteor.y_velocity = newspeed*Math.cos((backangle-180)*-1*(Math
.PI/180))*.90;

same for y

_root.meteor._x = tgt._x+((tgt._width/2+_root.meteor._width/
2)*Math.sin((backangle-180)*-1*(Math.PI/18
0)));

you havn't assigned a velocity for the meteor? isnt that just a one time hit?

couldnt you have just timesed it by backangle, instead of backangle - 180 then *-1? are you just trying to confuse people

_root.meteor._y = tgt._y+((tgt._width/2+_root.meteor._width/
2)*Math.cos((backangle-180)*-1*(Math.PI/18
0)));

blah blah same for _y

if (tgt.movableing == true) {
_root.meteor.x_velocity += tgt.xA;
_root.meteor.y_velocity += tgt.yA;
}

Damn is it really that late, where the hell is tgt.xA, does that even exist?

hit.setVolume(100);
hit.setVolume(newspeed*5);
hit.start();
}
}
}

Basically its an incomplete script for rebounding circular objects off eachother, but it appears to have been anally fucked.
WTF?

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Logic 2005-10-03 17:10:58 Reply

Ok I just read the part where it said these were pre used in your games, you can ignore my rant about "where the fuck is this variable" because I thought you had written them for the tut.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-03 17:14:20 Reply

At 10/3/05 05:08 PM, T-H wrote: blah

Pretty much correct. It's actually the function from Magnetism for the wooden spheres that bounce the meteor (ball bearing, i named it meteor cause it was copied and pasted from a gravity thing i did a long time ago and i didnt feel like changing it)

Teee-Haych
Teee-Haych
  • Member since: Sep. 18, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Logic 2005-10-03 17:17:23 Reply

At 10/3/05 05:14 PM, Glaiel_Gamer wrote:
At 10/3/05 05:08 PM, T-H wrote: blah
Pretty much correct. It's actually the function from Magnetism for the wooden spheres that bounce the meteor (ball bearing, i named it meteor cause it was copied and pasted from a gravity thing i did a long time ago and i didnt feel like changing it)

Cool, I wondered why the "meteors" didn't move themselves when hit.

I've always marveled at some of the programming concepts in that game. I'll have a dig at some of your other excercises another day when its not so late.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to AS: Logic 2005-10-03 17:45:58 Reply

At 10/3/05 05:17 PM, Teee-Haych wrote: Cool, I wondered why the "meteors" didn't move themselves when hit.

I've always marveled at some of the programming concepts in that game. I'll have a dig at some of your other excercises another day when its not so late.

Yea, developing the engine for the first one was pretty difficult.

If you look through my post history somewhere early on when I was a n00b I asked for a complex gravity code for planets. Then a few months later I decided to make a game with magnets. I already had a gravity code (even though i didnt write it) but i figured why write another. Well, i actually ended up hacking up the gravity code and reassembling it, tweaking values and adding stuff to make it more resemble magnetism than gravity. So in essence, i did write the magnetism code, but with the equation for gravity given to me by someone (dont forget im only a sophmore, havent taken physics yet). That was probably the easiest part. Circle hit tests got pretty complicated.

And for magnetism 2, well i barely had to write any new code, but I did do a lot of tweaking to my old code and re-wrote some parts.

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Logic 2005-10-07 06:45:04 Reply

Wow, this is one of the best ideas for an AS thread yet, IMO. Well executed too. <3


BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Logic 2005-10-07 07:13:42 Reply

wow dude, there are tons of mistakes there :-P

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Logic 2005-10-07 07:28:33 Reply

At 10/2/05 01:09 PM, Glaiel_Gamer wrote: ----------Introduction----------
Just knowing how to do actionscript and knowing the functions and such will not be sufficient enough to make an advanced game. Sure, you can go and make shooting games and simple enemy AI's and such, but it takes a lot more to make a game with complex AI or a complicated puzzle game. You have to be able to analyze the scripts and know what they do. Then, you have to be able to think up your own scripts.

I can't agree more :D

THE GOAL OF THIS THREAD:
---------------Part 1-------------
nmbr = 2
nmbr2 = nmbr*5
Now, you can just come to the conclusion that this script makes nmbr 2 = 10. Read every line of code.

sure you can :)

make a variable named number and set its value to 2
make a variable named nmbr2 and set its value to nmbr times 5

actually, if you insist, it is:
1)Check if a variable named nmbr exist, if not, allocate space for an Object instance
2)Find that the value two is assigned to the variable declared, the assignement occurs after the Number costructor is activated on nmbr
3)The process of decliration repeats for the nmbr 2, after it is declared the assignment occurs, like nmbr it is set, flash accesses your ram and fetches the data in nmbr's location, operated the ALU (arithmetical logical unit) of the computer to calculate using the multiply operator (which by the way the optimizer turns to >>2 which the computer can calculate much faster)

I know this is simple stuff, but that is exactly how the computer thinks.

this isn't simple at all ;) and the computer doesn't "think" it merely executes a queue of commands

Consider this:

nmbr2 = nmbr*5
nmbr = 2

Now, all I did was switch the 2 lines of code around. But this time, even though the code is pretty much the same, nmbr 2 will end up as NaN. Why? Because nmbr was undefined at the time nmbr2 = nmbr*5 was read by the computer.

because flash will attempt to fetch the data at nmbr's spot, and find nothing, the property nmbr does not exist for the current document, on real programming languages, nmbr2 will turn out as a value, but as a garbage value, any number that was stored that previously on the ram

Here's a slightly more complicated script involving function recursion.

you can recurse? hurrah!

function freeze(){
freeze()
}

no stoping point, no condition, and a pretty dumb recursive call

At first glance, that script might appear to be one that would freeze the computer. And yes it is, but just punching that into flash wont.

no, it won't, it'll get the computer into a stack overflow, but won't freeze it, flash will pop out that the function stuck exceeded a certein level of recursions and quit

Translated into how the computer thinks:

For the last time, a computer doesn't think

declares a function named freeze with no parameters with the following actions

again, it is a lot more compilcated than that, but overall that is correct I guess, the "actions" are really a block statement, and it does get a void parameter as well as an Object return value by default

call function named freeze
end of function

yep, where call the function means push the code pointer to the stack of calls as well as the parameters :D

That's it. ALl it does is declare a function.

that isn't simple at all...

But, the next 4 lines of code the computer treats as ? lines of code.
function freeze(){
freeze()
}
freeze()

Into computer language:

declare function, blah blah we know this part
call freeze
end of function
// now the computer calls the function it just made
call freeze
call freeze
call freeze
call freeze
...

the following line never really occurs:

end function

In essence, the computer gets stuck in an endless loop.

in essene? maybe, but due to how functions are implented it'll eventually reach a stack overflow

If you have a code that's buggy, all you have to do is read the code from top to bottom. If something doesn't seem right, break it down. Why wont it work? I have some examples at the bottom of this thread for you to try.

I totally agree with that

---------------Part 2----------------
So now you know how to read script. But how can you write complex scripts? Here's some more simple problems.

You want score to increase by 1 every 10 frames. How do you do it without set interval?

on enter frame
if 10 frames passed
increase var by one
end on enter frame

Well, seems like a simple problem, but you have to realize that the computer takes orders in a basic form.

which you don't access, flash won't take
MOV AL, 1
CMP CURRENTFRAME,10
JNZ notten
INC AL

not ten

, it is a lot simpler in flash

increasment code
Simple, eh?

function onEnterFrame(Void):Void{
_root.variable+=_currentframe%10==0;
}
simpler eh? :P

overall however, you did a great job, I'll cover more logic soon :)

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Logic 2005-10-07 07:38:39 Reply

At 10/2/05 01:09 PM, Glaiel_Gamer wrote: ----------Introduction----------
Just knowing how to do actionscript and knowing the functions and such will not be sufficient enough to make an advanced game. Sure, you can go and make shooting games and simple enemy AI's and such, but it takes a lot more to make a game with complex AI or a complicated puzzle game. You have to be able to analyze the scripts and know what they do. Then, you have to be able to think up your own scripts.

I can't agree more :D

THE GOAL OF THIS THREAD:
---------------Part 1-------------
nmbr = 2
nmbr2 = nmbr*5
Now, you can just come to the conclusion that this script makes nmbr 2 = 10. Read every line of code.

sure you can :)

make a variable named number and set its value to 2
make a variable named nmbr2 and set its value to nmbr times 5

actually, if you insist, it is:
1)Check if a variable named nmbr exist, if not, allocate space for an Object instance
2)Find that the value two is assigned to the variable declared, the assignement occurs after the Number costructor is activated on nmbr
3)The process of decliration repeats for the nmbr 2, after it is declared the assignment occurs, like nmbr it is set, flash accesses your ram and fetches the data in nmbr's location, operated the ALU (arithmetical logical unit) of the computer to calculate using the multiply operator (which by the way the optimizer turns to >>2 which the computer can calculate much faster)

I know this is simple stuff, but that is exactly how the computer thinks.

this isn't simple at all ;) and the computer doesn't "think" it merely executes a queue of commands

Consider this:

nmbr2 = nmbr*5
nmbr = 2

Now, all I did was switch the 2 lines of code around. But this time, even though the code is pretty much the same, nmbr 2 will end up as NaN. Why? Because nmbr was undefined at the time nmbr2 = nmbr*5 was read by the computer.

because flash will attempt to fetch the data at nmbr's spot, and find nothing, the property nmbr does not exist for the current document, on real programming languages, nmbr2 will turn out as a value, but as a garbage value, any number that was stored that previously on the ram

Here's a slightly more complicated script involving function recursion.

you can recurse? hurrah!

function freeze(){
freeze()
}

no stoping point, no condition, and a pretty dumb recursive call

At first glance, that script might appear to be one that would freeze the computer. And yes it is, but just punching that into flash wont.

no, it won't, it'll get the computer into a stack overflow, but won't freeze it, flash will pop out that the function stuck exceeded a certein level of recursions and quit

Translated into how the computer thinks:

For the last time, a computer doesn't think

declares a function named freeze with no parameters with the following actions

again, it is a lot more compilcated than that, but overall that is correct I guess, the "actions" are really a block statement, and it does get a void parameter as well as an Object return value by default

call function named freeze
end of function

yep, where call the function means push the code pointer to the stack of calls as well as the parameters :D

That's it. ALl it does is declare a function.

that isn't simple at all...

But, the next 4 lines of code the computer treats as ? lines of code.
function freeze(){
freeze()
}
freeze()

Into computer language:

declare function, blah blah we know this part
call freeze
end of function
// now the computer calls the function it just made
call freeze
call freeze
call freeze
call freeze
...

the following line never really occurs:

end function

In essence, the computer gets stuck in an endless loop.

in essene? maybe, but due to how functions are implented it'll eventually reach a stack overflow

If you have a code that's buggy, all you have to do is read the code from top to bottom. If something doesn't seem right, break it down. Why wont it work? I have some examples at the bottom of this thread for you to try.

I totally agree with that

---------------Part 2----------------
So now you know how to read script. But how can you write complex scripts? Here's some more simple problems.

You want score to increase by 1 every 10 frames. How do you do it without set interval?

on enter frame
if 10 frames passed
increase var by one
end on enter frame

Well, seems like a simple problem, but you have to realize that the computer takes orders in a basic form.

which you don't access, flash won't take
MOV AL, 1
CMP CURRENTFRAME,10
JNZ notten
INC AL

not ten

, it is a lot simpler in flash

increasment code
Simple, eh?

function onEnterFrame(Void):Void{
_root.variable+=_currentframe%10==0;
}
simpler eh? :P

overall however, you did a great job, I'll cover more logic soon :)

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Logic 2005-10-07 07:48:18 Reply

At 10/2/05 01:09 PM, Glaiel_Gamer wrote: ----------Introduction----------
Just knowing how to do actionscript and knowing the functions and such will not be sufficient enough to make an advanced game. Sure, you can go and make shooting games and simple enemy AI's and such, but it takes a lot more to make a game with complex AI or a complicated puzzle game. You have to be able to analyze the scripts and know what they do. Then, you have to be able to think up your own scripts.

I can't agree more :D

THE GOAL OF THIS THREAD:
---------------Part 1-------------
nmbr = 2
nmbr2 = nmbr*5
Now, you can just come to the conclusion that this script makes nmbr 2 = 10. Read every line of code.

sure you can :)

make a variable named number and set its value to 2
make a variable named nmbr2 and set its value to nmbr times 5

actually, if you insist, it is:
1)Check if a variable named nmbr exist, if not, allocate space for an Object instance
2)Find that the value two is assigned to the variable declared, the assignement occurs after the Number costructor is activated on nmbr
3)The process of decliration repeats for the nmbr 2, after it is declared the assignment occurs, like nmbr it is set, flash accesses your ram and fetches the data in nmbr's location, operated the ALU (arithmetical logical unit) of the computer to calculate using the multiply operator (which by the way the optimizer turns to >>2 which the computer can calculate much faster)

I know this is simple stuff, but that is exactly how the computer thinks.

this isn't simple at all ;) and the computer doesn't "think" it merely executes a queue of commands

Consider this:

nmbr2 = nmbr*5
nmbr = 2

Now, all I did was switch the 2 lines of code around. But this time, even though the code is pretty much the same, nmbr 2 will end up as NaN. Why? Because nmbr was undefined at the time nmbr2 = nmbr*5 was read by the computer.

because flash will attempt to fetch the data at nmbr's spot, and find nothing, the property nmbr does not exist for the current document, on real programming languages, nmbr2 will turn out as a value, but as a garbage value, any number that was stored that previously on the ram

Here's a slightly more complicated script involving function recursion.

you can recurse? hurrah!

function freeze(){
freeze()
}

no stoping point, no condition, and a pretty dumb recursive call

At first glance, that script might appear to be one that would freeze the computer. And yes it is, but just punching that into flash wont.

no, it won't, it'll get the computer into a stack overflow, but won't freeze it, flash will pop out that the function stuck exceeded a certein level of recursions and quit

Translated into how the computer thinks:

For the last time, a computer doesn't think

declares a function named freeze with no parameters with the following actions

again, it is a lot more compilcated than that, but overall that is correct I guess, the "actions" are really a block statement, and it does get a void parameter as well as an Object return value by default

call function named freeze
end of function

yep, where call the function means push the code pointer to the stack of calls as well as the parameters :D

That's it. ALl it does is declare a function.

that isn't simple at all...

But, the next 4 lines of code the computer treats as ? lines of code.
function freeze(){
freeze()
}
freeze()

Into computer language:

declare function, blah blah we know this part
call freeze
end of function
// now the computer calls the function it just made
call freeze
call freeze
call freeze
call freeze
...

the following line never really occurs:

end function

In essence, the computer gets stuck in an endless loop.

in essene? maybe, but due to how functions are implented it'll eventually reach a stack overflow

If you have a code that's buggy, all you have to do is read the code from top to bottom. If something doesn't seem right, break it down. Why wont it work? I have some examples at the bottom of this thread for you to try.

I totally agree with that

---------------Part 2----------------
So now you know how to read script. But how can you write complex scripts? Here's some more simple problems.

You want score to increase by 1 every 10 frames. How do you do it without set interval?

on enter frame
if 10 frames passed
increase var by one
end on enter frame

Well, seems like a simple problem, but you have to realize that the computer takes orders in a basic form.

which you don't access, flash won't take
MOV AL, 1
CMP CURRENTFRAME,10
JNZ notten
INC AL

not ten

, it is a lot simpler in flash

increasment code
Simple, eh?

function onEnterFrame(Void):Void{
_root.variable+=_currentframe%10==0;
}
simpler eh? :P

overall however, you did a great job, I'll cover more logic soon :)

Murch
Murch
  • Member since: Feb. 26, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS: Logic 2005-10-07 07:54:55 Reply

why did you spam it inglor :P?

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Logic 2005-10-07 09:25:04 Reply

I thought it didn't post the first time...

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Logic 2005-10-07 09:56:06 Reply

At 10/7/05 09:25 AM, Inglor wrote: I thought it didn't post the first time...

Haha. That was a nice post explaining everything. Now, when are you going to get back from that fuckfest country?


wtfbbqhax