playMaker

Author Topic: Array, how to check items and their index. SOLVED  (Read 1580 times)

Stain Corb

  • Junior Playmaker
  • **
  • Posts: 69
Array, how to check items and their index. SOLVED
« on: January 08, 2020, 11:21:00 PM »
Hello all.

So far every time I have tried using Arrays I just discard them every time and use INTs. so I wont explain my failed tries. I will explain what I need to do.

I have a character with 2 hands = ArrayList of 2, So say, I add ItemA into ArrayList at index1 and then add ItemB into ArrayList at index2, I need to be able to check What items are at what Indexes and or if array is empty in those indexes.

What action can I use for this ?, I have gone trough a lot of Actions each giving me results I cant or dont know how to use.

I need to compare object in the Arrays with their indexes to decide how to place Items, Etc...

I can do this with INTs but it will be crazy setup If even possible, so I would like to use arrays. Also my game is supposed to have many items, I cant get past 2 different items  :'(.

Any help would be greatly appreciated.

« Last Edit: January 15, 2020, 08:46:57 PM by Stain Corb »

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Array, how to check items and their index.
« Reply #1 on: January 09, 2020, 12:38:46 AM »
Heya,

This will all depend heavily on your setup and/or design but this could be a way to try it.

You'll need 2 arrays, one for your Character hands (Left and right hand which you already have) and an Item Database array.  The item database array will have every item you could equip in it.  Whatever that item has for an index will be its ID number.  Then your character hands array can simple use the ID number when set to find what item it is. 

So for Ex Item database will be 0=nothng 1=sword =2 shield.  Character array can be 0,2 (Nothing and Shield) or 1,1 (duel wield swords) 1,2 (sword and shield) ect.  Any time the character hands array changes, have it re-check what it has equip and apply the stats accordingly.

Let me know if that helps.

Stain Corb

  • Junior Playmaker
  • **
  • Posts: 69
Re: Array, how to check items and their index.
« Reply #2 on: January 11, 2020, 11:13:50 PM »
What happens if I am adding these arrays with pickups, there fore it will be adding into the array in disorder, IDs will be different every time, how would be the best way to get these objects ? by object ID ?

Be cause I was actually thinking of using your idea but with INT, but I did a simple calculation and I am over 10 items in the game document and would have more in the future so I would have to specify each weapon into a specific INT number, but this will be slow.

So ArrayList should solve this issue right ?
I assume I could Check the Array list for Items or non items and quantity of the same items Right. ?

Any other ideas I could possibly use, for item picking up, crafting and item getting robed?

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Array, how to check items and their index.
« Reply #3 on: January 12, 2020, 10:01:04 PM »
Heya,

The Item Database array would be a constant array basically.  It is there for reference only and shouldn't be adjusted once the game starts. 

For Example.  Say the Item Database has Sword for index 1. The player runs into a Sword for pick up.  The sword has a FSM with ID Value on it as 1.  1 gets added to player hands array.  Another FSM watches the players hand array for changes.  That FSM sees the index change and looks at the Item database and knows now ID 1 means its a Sword. 

From there it all depends on what you want to happen when they pick it up.  This should be able to apply to all different situations as well.

Stain Corb

  • Junior Playmaker
  • **
  • Posts: 69
Re: Array, how to check items and their index.
« Reply #4 on: January 13, 2020, 09:47:52 AM »
Ok I get it, I am just confused a bought one thing, If its static, why not just use INTS, would ArrayList be better  ? or is it simply choice of what I prefer ?

Stain Corb

  • Junior Playmaker
  • **
  • Posts: 69
Re: Array, how to check items and their index.
« Reply #5 on: January 15, 2020, 08:46:11 PM »
I will use Ints at the moment and look into Array for the future of this project.

Thanks for your help.