Be a Supporter!

[as2] Inventory Help (array System)

  • 2,267 Views
  • 36 Replies
New Topic Respond to this Topic
flashMan
flashMan
  • Member since: Aug. 24, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to [as2] Inventory Help (array System) Feb. 25th, 2013 @ 05:23 AM Reply

At 2/24/13 10:03 PM, Diki wrote:
At 2/24/13 08:35 PM, cheese123 wrote: The for loop seemed unnecessary ... I just needed the while loop
You know that the only significant difference between a while loop and a for loop is syntax, right?
They're both loops and can break your application if used incorrectly.



If you don't understand the difference between the assignment operator and the equality operator then you can't know them well enough to be able to use them to do what you want. They are very different operators and cannot be used interchangeably.

thanks for all the info! and yea normally if something like 'if(x=y)' wouldn't work, i would just resort to 'if(x==y)' not really knowing the difference. yea you guys might cringe at that :P

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to [as2] Inventory Help (array System) Feb. 25th, 2013 @ 01:37 PM Reply

At 2/24/13 09:57 PM, MintPaw wrote:
At 2/24/13 08:23 PM, Rustygames wrote: Don't use a language over 6 years old. Really? I hope you realize how silly a comment that was :)
Meh, I probably could of rephrased that "Don't use a language that was last relevant over 6 years ago."
The only reason you'd use AS2 at this point is you're too lazy to get up-to-date, it costs nothing but time and effort, I've almost completely resolved to not take the time to help people who won't take the time to help themselves.

Sorry I guess I was being a bit of a pedant :)
People not wanting to take up time and effort to learn I can understand (although it really doesn't take a lot to move from one to the other!), but then coming and asking for help and not willing to take it on board if it requires any effort does my head in as well!

At 2/25/13 04:05 AM, Filipus wrote: 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!".

Sorry we went off topic and didn't help, unfortunately I don't think any one who replied is willing to help you learn how to code unless it's in AS3


- Matt, Rustyarcade.com

Filipus
Filipus
  • Member since: Feb. 18, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to [as2] Inventory Help (array System) Feb. 25th, 2013 @ 05:46 PM Reply

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 :)

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to [as2] Inventory Help (array System) Feb. 25th, 2013 @ 06:15 PM Reply

At 2/25/13 05:46 PM, Filipus wrote: 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 :)

Cool show us :)


- Matt, Rustyarcade.com

PMMurphy
PMMurphy
  • Member since: May. 27, 2012
  • Offline.
Forum Stats
Member
Level 01
Programmer
Response to [as2] Inventory Help (array System) Mar. 31st, 2013 @ 05:12 AM Reply

I don't even program in as2 or as3 or as1902381023948209348

I googled some stuff about it.

as2 doesn't have an arraylist class.

Why are you programming in as2 again?

NecroBlight
NecroBlight
  • Member since: Feb. 20, 2010
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to [as2] Inventory Help (array System) May. 11th, 2013 @ 04:43 AM Reply

I'm not sure if S@ has it, but with AS3 you can use flash's Listing component for inventory.

Filipus
Filipus
  • Member since: Feb. 18, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to [as2] Inventory Help (array System) Jun. 12th, 2013 @ 10:12 AM Reply

By 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