PDA

View Full Version : Need a person to write Simple Array for me.



Brandon?
August 9th, 2004, 08:10 PM
Don't think im dumb are anything but i need someone to write a simple array for me though all my actionscripting ive never had to do it before and I really dont have the time to learn now. Let me descirbe what has to be done really simple and then ill send you a test dummy to add the code to. The game this is for is almost completed and is one of my best creations yet.
Description:
My game consists of thousands of hit tests that all work together to stop the unit from running though small objects. (mostly alot of trees and walls).
I know nothing about arrays. Heres the simple hit test all you have to do is make the number after T everynumber possible.
if (this, hitTest(_root.world.T+[i])) {
okay if you accept this job you will be included in the Credits. The file is attached, when done send it to (with the name you want to be known as under the credits):
Darktemplarian8@aol.com

Brandon?
August 9th, 2004, 08:12 PM
oh ya the file is just for you to work with it isnt the game just a tensil to write the code on and send to me. Note the tensil does contain all the movement code so you can test it. Just wanted to clear that up.

Prophet
August 10th, 2004, 02:04 PM
how many numbers are there? in the fla there are 2 T integers and 4B integers.... do you want B to be included as well?
and btw this isnt just a simple array job either...

Prophet.

Brandon?
August 10th, 2004, 02:28 PM
yes T is for only trees and B is for the Misc objects like walls and stuff

Brandon?
August 10th, 2004, 02:30 PM
so are you going to try and write an array for me becuase i am almost done with most of the games major codings then im going to start the maps Story line and i really need that code for my unit.

Brandon?
August 10th, 2004, 06:29 PM
like i said im almost done with my coding for my Game and need to test out a few other things so someone please just write the code and send me the thing please I want to start testing my games quests and other code as soon as possible. k thanks

Prophet
August 10th, 2004, 07:38 PM
keep ya wig on ill give it a whirl but im not sure...
ne others want to hav a crack at it be my guest

Prophet.

PS ill PROBABLY (no promises) be on again tomoro (lookin at the time its actually later today...) at 6pm GMT

Brandon?
August 10th, 2004, 09:08 PM
Sounds Great like he said Please if anyone else wants give it a try. Thanks agian.

Brandon?
August 12th, 2004, 12:52 AM
yes i'm still waiting for anyone to try and figure this out had a few views but no real help except Prophet who seems to help alot of people. K someone reply with some help.

Prophet
August 12th, 2004, 06:17 PM
thanks i do my best ;)
altho i gotta admit im a lil 2 busy to giv urs (or that musical rotating ball thingy :S) enough time atm im afraid....

i log on every day (if i can) and help other ppl coz it helps me in cementing the basics and broadening my own experience :) id reccomend helping to all those question askers out there! ;) lol

Prophet.

Brandon?
August 12th, 2004, 07:50 PM
well any others i would highly like you to look at my FLA and try and write an array for it if you could. Thanks becuase im not getting far working on it myself

Mike D
August 12th, 2004, 09:31 PM
Here's a related question:

I start with a variable called allnumbers:

for (allnumbers=0; allnum<50; allnum++) {
trace("_root.world.T"+allnum);
}

and the output looks like this:


_root.world.T0
_root.world.T1
_root.world.T2
_root.world.T3
...
_root.World.T49


How do I use this variable to perform a hit test on multiple instances (_root.world.T1, _root.world.T2...)? I thought that something like this would work:

if (_root.Unit, hitTest(_root.world.T+allnumbers)) {...}
...but it doesn't

Brandon?
August 12th, 2004, 09:41 PM
Ya im confused by this too and ive tryed about every way possible the only way ive been told this can be done is with and array and i dont know anything about them and have gone far without using them and i dont want to learn them just for this reason. If you can't figure it out just do the long way:

if (_root.Unit, hitTest(_root.World.Tree1) or _root.Unit, hitTest(_root.World.Tree2) or _root.Unit, hitTest(_root.World.Tree3)) { ext... lol

Oh ya someone please Help me on the real priority if you could find the code i know it would help alot of game Actionscripters. Thanks

APDesign
August 13th, 2004, 12:37 AM
Add this to the top of the blue dudes AS


onClipEvent(load){
numTrees = 6;
checkTrees = function(){
for(var i = 1; i< numTrees+1; i++){
if(this, hitTest(_root.world["T"+i])){
return 1;
}
}
}
}


then Instead of using if(this, hitTest()) blah blah blah for each direction, just replace it with this...



if (checkTrees()) {


Copy the trees and number them T1, T2, T3, T4, T5 etc.. so if you use 5 trees, you would have T1-T5 and the numTrees variable would be 5. If you use 6 trees, change the numTrees variable to 6, etc.. etc..

Here's the .fla (had to zip it, too big.. sorry).

Oh yeah.. no Array required either. I'm not sure what this talk of "B" is, but this should give you some ideas. Maybe make something like this


onClipEvent(load){
numTrees = 6;
checkTrees = function(){
for(var i = 1; i< numTrees+1; i++){
if(this, hitTest(_root.world["T"+i])){
return 1;
}
}
}

numObjects = 4;
checkObjects = function(){
for(var i = 1; i< numObjects+1; i++){
if(this, hitTest(_root.world["B"+i])){
return 1;
}
}
}

}


and then change the if...


if (checkTrees() && checkObjects()) {


I didn't test the objects, but I tested the trees....

Brandon?
August 13th, 2004, 01:26 PM
Thanks
Just one more thing your middle code, if you have both hit tests should be or like this,
if (checkTrees() or checkObjects()) {
thanks again.

Prophet
August 13th, 2004, 02:18 PM
yer thas probly y i culdnt think of a simple way of doing this! lol

if((checkTrees() || checkObjects()){
}
sorry i couldnt b of more help tho :(

Prophet.

Mike D
August 13th, 2004, 03:54 PM
Can someone please explain what the last line of the function does?



onClipEvent(load){
numTrees = 6;
checkTrees = function(){
for(var i = 1; i< numTrees+1; i++){
if(this, hitTest(_root.world["T"+i])){
return 1;
}
}

APDesign
August 13th, 2004, 05:48 PM
Can someone please explain what the last line of the function does?



onClipEvent(load){
numTrees = 6;
checkTrees = function(){
for(var i = 1; i< numTrees+1; i++){
if(this, hitTest(_root.world["T"+i])){
return 1;
}
}




Just like the normal hitTest() function, it returns 1 if there there is indeed a "hit" and returns 0 if there isn' a hit, which is what makes the if(checkTrees()){ work.

Prophet
August 13th, 2004, 08:49 PM
note that boolean values true or false can be substituted for 1s and 0s....
hence y the if statement works if there has been a hit - the function has returned true and therefore sets off the if statement ;)

Prophet.

Mike D
August 13th, 2004, 09:23 PM
Thanks, I thought that may have been the case.

Mike D
August 13th, 2004, 10:01 PM
I changed some of the code you had used Brandon. I removed the stutter from the walking script by using _root.onEnterFrame instead of onClipEvent(KeyDown). Also I increased the frame rate to 30 and reduced the distance the world moves every frame to 2. This creates a smoother animation. Check the attachment to see and test the code.

Mike D
August 13th, 2004, 11:23 PM
|| is the same as or, but it is preferred because sometime in the future, or will not be recognized by the Flash player. This is the same thing with && and and.

Brandon?
August 14th, 2004, 08:58 PM
Ya somethings wrong with the code becuase if you tested it and tried to run "down" into one of the 0 degree trees you wern't able to move right. and then the unit gets stuck all the time and thats just annoying for the person playing the game. it seems to do it wen i use that code but when i use the code the other way it works fine. So you might want to retest this code by testing it. Ya i did take your advise and i changed the speed to 24 to make it more smooth.
"note: the shorter code isn't always the best code."
And thanks to you all for helping me out. (just to tell you this game is set up like a game boy game you go around and hit space and talk to people and do little quests.)

APDesign
August 14th, 2004, 10:17 PM
Wait, my code didn't work??!?! It seemed to work for me :(

Did you try the .fla?

My .fla worked fine for me.

Mike D
August 15th, 2004, 12:21 AM
Brandon, whose code are you saying didn't work properly? The fla I posted works fine for me. Here's my code in case it has changed (I did add a speed variable.....)


onClipEvent (load) {
numTrees = 7;
checkTrees = function () {
for (var tr = 1; tr<numTrees+1; tr++) {
if (this, hitTest(_root.world["T"+tr])) {
return 1;
}
}
};
numObjects = 5;
checkObjects = function () {
for (var obj = 1; obj<numObjects+1; obj++) {
if (this, hitTest(_root.world["B"+obj])) {
return 1;
}
}
};
speed = 2;
}
onClipEvent (enterFrame) {
_root.onEnterFrame = function() {
if (key.isDown(key.LEFT)) {
_root.World._x += speed;
_root.Unit._rotation = 270;
if (checkTrees() || checkObjects()) {
_root.World._x -= speed;
}
} else if (key.isDown(key.RIGHT)) {
_root.World._x -= speed;
_root.Unit._rotation = 90;
if (checkTrees() || checkObjects()) {
_root.World._x += speed;
}
} else if (key.isDown(key.UP)) {
_root.World._y += speed;
_root.Unit._rotation = 0;
if (checkTrees() || checkObjects()) {
_root.World._y -= speed;
}
} else if (key.isDown(key.DOWN)) {
_root.World._y -= speed;
_root.Unit._rotation = 180;
if (checkTrees() || checkObjects()) {
_root.World._y += speed;
}
}
};
}

APDesign
August 15th, 2004, 04:04 AM
Brandon, whose code are you saying didn't work properly? The fla I posted works fine for me. Here's my code in case it has changed (I did add a speed variable.....)


I haven't tested this code, but my code works and I'm pretty darn shure that if(checkTrees()||checkObjects()){ works, lol.