An easier way to store 'stats' of 'items/weapons'?

PressXtoNotDie

  • Posts: 94
Currently what i am doing is storing 'stats' of items or weapons in separate lists.
for example:
Weapon Names - List 1
0 - dagger
1 - sword
Weapon Damage - List 2
0 - 3
1 - 6
Weapon Equip Slot - list 3
0 - hand
1 - hand

Etc. etc. etc.

I just want to know if there is a better way of doing this before I go too far ahead with this.

rancid1

  • Posts: 46
You could give each weapon a unique behavior that handles it's stats. Just a thought.

There would probably be a significant amount of code duplication though. :\

I suppose some of that could be avoided by handling the weapons "actions" and "stats" in different behaviors. (ie, have the Stats behavior set things up, and the Action behavior gets the stats when acting.)
See my other work at: http://www.rancid1.com

ShivaFang

  • Posts: 248
I personally prefer creating custom classes to do this and then pass the item around as an object.  Not handled natively by Stencyl though and requires actual code pages as well, not just block designer code.

Then you could store all the weapons in a list and then call Weapon.Name, Weapon.Damage and Weapon.Slot to get the information (again, using code blocks)
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

captaincomic

  • *
  • Posts: 6108
Another option would be a list of lists.
The weapons list would contain a number of lists, each of those lists represent one weapon and contain name, damage and slot.

PressXtoNotDie

  • Posts: 94
@rancid1
Yeah I thought of doing it like that, but like you said, there would be a lot of duplicate code.

@ShivaFang
That does seem like a much better way, but I haven't dived into coding in Stencyl at all yet, so that would be far far ahead of me.

@captaincomic
List in a list? I have not tried that yet, i didnt even know that was possible. I will have a play around with Stencyl, and see if I can figure it out.
Do you have a small example you could show me maybe?

PressXtoNotDie

  • Posts: 94
Would this even be close to what you are talking about? [In attachment at the bottom]
I have no idea if it works, since, i dont know how to retrieve what i want.

If i want to retrieve the Damage (Which is 6) from the sword (list item two) How would i go about doing that? That is, if what i've done is even CLOSE to being right...

ShivaFang

  • Posts: 248
A list of lists is a good idea.

You are essentially doing it right.
EDIT:  Except you need to add another 'add [Create New List] to [WeaponList]' after the Sword comment.  You need to add a new list to WeaponList for each weapon you are making.
 So if you wanted to get the power of a sword, you would do something like;

Code: [Select]
get the value of item #[1] of [get the value of item #[1] from [WeaponList]].
Another thing you can do is when the item is equipped on the character, you only need to keep track of the weapon number, so you character's 'equip' variable would be '1' for a sword, so you could do this...

Code: [Select]
get the value of item#[1] of [get the value of item #[equip] from [WeaponList]] which will always give you the power of the equipped weapon as long as you set 'equip' right.



I'd LOVE to be able to create 'custom objects' where you can assign attributes kind of like you do with actors and behaviours, without having to code them up each time.  It would be easier to use them in block arrays, and you could assign them 'types' like you do with actors, so you'd be able to do "If [object] is of type [type]"

Call them objects, or props or whatever, it would make stuff like this SO MUCH EASIER and doesn't seem to far out of the existing framework.  ('Maps' aka Dictionaries would accomplish a similar role, though, I think.)

« Last Edit: May 10, 2012, 06:44:49 pm by ShivaFang »
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

captaincomic

  • *
  • Posts: 6108
@PressX yes, that's what I meant.
@ShivaFang thanks for explaining things further. :)

PressXtoNotDie

  • Posts: 94
Thanks guys for your help, this is some really good stuff, a much much better way than 3 separate lists. Can finally start implementing what I need =)

ShivaFang

  • Posts: 248
Yes!  I actually learned something too, never thought about doing it as a list of lists (or 2 dimensional array).  I'm planning on eventually expanding into mobile distribution and you can't distribute mobile if most of your code is in AS3 :o so I have to move away from custom classes and try to do more with blocks.

So your question, and captincomic's reply, got me to think about it in a different way :).
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

captaincomic

  • *
  • Posts: 6108
You might also want to take a look at Sunflowers custom blocks for 2D arrays, you can find them on StencylForge. I didn't try them, but they look very useful.

Nathbo

  • Posts: 388
Hmmm.. maybe I need a little help with this..

Right now I have 3 different lists to hold my completed levels
1 for completedlevels (holds 1 or 0 for true false) for my 64 levels
2nd for unlocked levels (again 1 or 0) for my 64 levels
3rd for completedtime (holds 1 or 0) for my 64 levels

And I plan to add themes to my game...
So can I then share the same list but using a master list of themes ??
Like CompletedThemeList holds 3 copies of completedlevels list ??

Thanks
Visit my Facebook page
http://www.facebook.com/NathboGames

Twitter
@NathboGames