Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsBy http://progressstudios.newgrounds.com/
I noticed your frustration of trying to get a inventory system working in AS2
I highly recommend you move to as3 but for now I will tell you how a inventory system works in as2. Before you start coding you need to know how the code gets executed and what happens first, how fast it gets executed.
I will tell you the easiest way to do this, You can start by making a Movie Clip. This Movie clip will be your inventory slot
The first frame of the movieclip will be a empty slot, The second frame will be a slot with a item in example (HP potion), The third frame will be a slot with another item in, For example a mana potion.
You then need to make an array, With empty strings in for how many inventory slots you got
var invarray:Array = new Array("Empty", "Empty", "Empty");
Lets say we have 3 inventory slots
An Array will hold multiple values, In this case we are going to pass our items as strings.
Then after the array is made you need to make a function which will add items to the array
So lets start
function AddItemToMyArray(item:String)
{
var addonce:Boolean = false;
for(var a=0;a<invarray;a++)
{
if(!addonce)
{
if(invarray[a] == "Empty")
{
invarray[a] = item;
addonce = true;
}
}
}
DisplayItem()
}
The add once variable stops the for statement finding all slots that are empty and just finds the first one
After this we need to display the items in the inventory
As you can see we call this function from the AddItemsToMyArray function
function DisplayItem()
{
for(var i=0;i<invarray;i++)
{
if(invarray[i] == "ManaPotion")
{
invSlotsArray[i].gotoAndStop(WhatFrameyourManaPoti onIsOn)
}
if(invarray[i] == "HPPotion")
{
invSlotsArray[i].gotoAndStop(WhatFrameyourHPPotion IsOn)
}
}
}
As you can see we have declared something called invSlotsArray, This will hold your inventory slots.
Now go back to the top and make it
var invSlotsArray:Array = new Array(_root.invs1, _root.invs2, _root.invs2)
This will hold your inventory slots, Now go back to your scene and copy the inventory slot we made earlier, Now there are 3, Give them a instance name of invs1, invs2 and invs3.
If anything was wrong or you don't understand, I made these tutorials a few years back
http://www.youtube.com/watch?v=btl5X_Ic68o
At 6/6/13 06:46 PM, Filipus wrote: Ok, sorry again for the spam but i discovered a error I made.
I was putting the variables inside the onEnterFrame funcion...
It seems to be working now! Sorry for the trouble guys!
This really needs an edit button...
If anyone with the same errors as mine need help here are the AS files.
http://mc.tt/16ClET79ugJ
-I solved the problem of reseting the getTime() thing.
-You now have bestTime in Multiplayer
again, sorry for the spam, but this may help someone :)
Ok, sorry again for the spam but i discovered a error I made.
I was putting the variables inside the onEnterFrame funcion...
It seems to be working now! Sorry for the trouble guys!
At 6/6/13 05:38 PM, kkots wrote: You're putting your code in the wrong place. I can see that by how you use "this" to refer to something which is probably a MovieClip or a Sprite.
something.hitTest(this);
And that means you have a MovieClip, since that's the only reason that could cause your problem - MovieClips have multiple frames, and your code is in a frame inside some movie clip (probably a car), and the code keeps being ran every time the frame is entered. Then you need to wrap all your code in this statement to make it run once only:
if(!firstTime){
firstTime=true;
//the rest of hitTest and laps code
}
Well, my code is done this way.
I have a menu that calls a class.
In that class I import the sprites of the track and car (trough addChild).
I then created an actionscript for the car so that i could code the movement and all that.
I have an ASLinkage so it calls this script.
here's a link for the fla and all rest
http://mc.tt/6aClCILm8KJ
Maybe i should do the timer inside de timermc?
I actually liked the game a lot.
Better visuals would be fantastic and when in zoom out a bit less of zoomout.
And when it does the animation it blocks the clicking 0.5-1 second after it.
At 6/6/13 05:00 PM, Filipus wrote:
I KNOW IT!
LET ME TEST SOMETHING :3
Sorry for the spam but i can't edit my posts...
I tried to create a "checkpoint" but it didn't really work.
I dont know why but my if keeps running even if the condition is false....
At 6/6/13 06:56 AM, nitokov wrote: Why use hittest which is cpu intensive when you can use simple math.
How can i use simple math?
also i wouldnt use timer class for this at all, its not reliable enough for me.
You can have timer:int = 0 at start and when race is started every frame you add timer+=1. so
time = timer / framerate seconds
I have multiplayer so i was trying to get a precise time (in milliseconds). I dont think that way enables me to do that. But i'll think about it, thanks! :)
when you use getTimer() you get time which started when your movie starts (i think).
No, only when you start the timer.
:and you can use some booleans vars to double check if car is passed finish line and if new lap is running.
Well i actually tried that and it didn't work.
var contadorbest:Boolean = false;
if (par.finishline.hitTestObject(this)) {
if (!contadorbest)
{
laps++;
contadorbest = true;
lastTime = (elapsed/1000) - lastTime;
}
(at the end of the code i make it false again... WAIT A SECOND!)
I KNOW IT!
LET ME TEST SOMETHING :3
At 6/6/13 06:41 AM, kkots wrote: elapsed=new Timer();
If I am not mistaken, you are trying to divide a Timer by 1000?
elapsed/1000
Or I am seeing things?
I'm dividing so that i can get the seconds..
Math.floor(elapsed/1000)+"."+(elapsed%1000);
Is it wrong or... ? It works fine from what i see.
Ok guys i'm making a racing game and using the class Timer to calculate how much time has elapsed and what is the best lap.
Everything works fine, i just have one small problem... When the car hittests the finish line, he runes the code a bazzilion times (screwing my bestlap thing ): ).
I've tried putting a variable and only running the code when variable > 7 but the hittest still does the same (while the rest not).
Here's the code I'm using now. As you can see i tried a new thing (number of laps) but the problem is the same.
var elapsed = getTimer();
var contadorbest = getTimer();
if (par.finishline.hitTestObject(this)) {
if ((contadorbest/1000) > 7)
{
laps++;
contadorbest = 0;
lastTime = (elapsed/1000) - lastTime;
par.besttimer_MC2.besttimer.text = laps.toString();
if(bestTime > lastTime)
{
bestTime = lastTime;
//par.besttimer_MC2.besttimer.text = bestTime;
}
}
}
par.timer_MC2.laptimer.text = Math.floor(elapsed/1000)+"."+(elapsed%1000);
Any tips? Thank you in advance :)
Well, cheese helped me and i already have a working inventory. I'll post the results tomorrow (the fla file) to help the little nobbies like me :)
Ok i PM you cheese.
restnothelping@
I already said i will move to AS3 after this. But i want to finish this AS2 project now. Its an inventory guys, it should't be that much work. You are all making a big fuss out of it. "AS2 is outdated, i wont help because you'r stupid if you use it!".
At 2/22/13 12:21 PM, cheese123 wrote: I'm a newb too.
Are you looking for something that works like this?
http://www.newgrounds.com/dump/item/14194fd8efb885097be7ce14 cc4da0f7
Do you really know how arrays work?
for instance, if I have a dynamic text box with an instance name 'people':
names = ['toby','john','fred']
i = 0;
people.text = names[i]
What will the text box show me? If you can't answer that much, you need to go to basics.
Toby.
Arrays start at 0 if i remember correctly.
And that is exactly what i want! :D
The drag and combine thing i can handle.
----------------------------
@guyabove
Hm... I had never heard of that so i'll have to look into it. Thanks for the help :)
At 2/22/13 07:25 AM, Jin wrote: You must assign a function to an onRelease handler.
Function arguments have a name and a type.
I know perfectly well how arrays and functions workNo you don't. Stop lying.
They have a type? Like this.Item1.onRelease = addItem(Item1:String) ?
Well, i tough i knew... Maybe i dont ),:
I'm reading lots of articles/tutorials, let's see if i understand what you meant
At 2/21/13 03:58 PM, Rustygames wrote:At 2/21/13 01:24 PM, milchreis wrote:My comment would be a less harsh version of the above.At 2/21/13 10:54 AM, Filipus wrote: I did a this.Item1.onRelease = addItem(Item1);You know nothing about As2. You're nowhere near anything in this project.
Isn't that the right method?
Stop copy&pasting horrible code that you don't understand.
Code this in As3.
Do it in AS3, you do not have anything done yet. You'll also need to read up on the basics of coding; arrays and functions are really basic concepts you must first understand before making anything
I know perfectly well how arrays and functions work, i just can't implement them well in AS2.
I have already done things (that are something to me), that image isn't the project... It was just an inventory test.
Can you guys please help instead of trying to put a guy down? I just need help with this then i will go to AS3. Please?
At 2/20/13 12:38 PM, LunarHawk69 wrote:
:lovelythingsshewrotebecauseshesawesome
Ok, i tried it but it seems it isn't working (I've uploaded an image).
I named the objects, i linked them (export to actionscript right? To give an identifier so that you can pull them from the library by the name) and i even tested some other functions to see if i was doing something stupid haha.
The way i'm trying to do is that by clicking in the object he goes to the inventory.
I did a this.Item1.onRelease = addItem(Item1);
Isn't that the right method?
Can't you do it by creating a counter? Var:counter and then ++ it everytime you click?
then it would just need a for loop
for/if/while (counter=1)
this.textobox = "blablabla".
I dont know, i'm new to AS too haha.
By the way, you have this great topic http://www.newgrounds.com/bbs/topic/638183 with lots of tutorials.
And there you have a OOP one http://www.newgrounds.com/bbs/topic/297981
At 2/19/13 01:13 PM, Spysociety wrote: Yes it makes you looks like lazy.
Anway, first since you are new to actionscript, I not only suggest but highly recommend changing to AS3. Second, do not code inside symbols. Third start by the simplest things, an inventory is not so easy of cake for beginning with.
Play a bit with arrays, follow the Actionscript 3.0 Language Reference and any doubts you might come in just post here in the forum, people will be willing to help someone who made the code themselves.
Yea man but the problem is that this is a project i promised myself i would do and i already have lots of things done. After this i will move on to AS3 .
I needed something like this http://www.newgrounds.com/dump/item/d4133964b68c00e7712fd4bd 11603e54
Now, i know in theory what i need. I know i need to create a certain number of inventory boxes, name the items and then make an array so that i can do something like
[sword,1]
[pencil,2]
[thing,3]
Right?
Like i said, i know it sounds lazy but its not the case. I really need help with this and a fla. would be great (believe it or not that is how i learn better, seeing the thing done and then after understanding how it works make one for myself (I dont copy+paste)).
This is for a Point and Click Game!
Ok guys i really need help with this. I have read every topic regarding inventories here on NG but i just dont get it...
I can easily do the on(press) system but that isn't very smart when i'm planing using a lot of objects i think.
I understand how array works but i can't make it work (i'm really new to AS).
Can someone help me with code? I know it seems i am going the lazy way but its not the case, i just can't make it work.
A working fla would be wonderful and would really help.
Thanks by the way :)