"Best" way to implement movesets and items.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By johnnywycliffe

I’m working on a turn based RPG and am currently attempting to integrate a moveset and to a lesser extent an item system which will work similarly. I’m using Godot 3.0.6 and GDScript.

From research around the internet, I decided that my options are:

  1. JSON file serialization and load, to keep all the data out of RAM. Probably the best option.
  2. A giant list of dictionaries representing moves/items. This sounds like a terrible idea, as then each fighter would have a copy of those in it’s move list and then my game will eat more RAM then chrome.
  3. In some other languages, I know you can create a bunch of functions and call them dynamically. (C#) Can I set up something like guard(), kick() and punch() and add them to a list to use?

I know how to do the first two, just not sure of which would be better. I don’t know if the third is possible, or a good idea if it is.

Thank you in advance.

:bust_in_silhouette: Reply From: MysteryGM

1.) Good idea. I never used JSON personaly, but a lot of developers I know do; they say it is fantastic for modding and quick updates.
Mostly the data you keep out of ram will be level stuff and assets, the next point explains.

2.) Dictionaries and lists actually work fantastic for this. The reason is that classes like this is insignificant compared to other resources.
For example a single sprite could consume 1-4 MB of Ram but a list of over 1 000 abilities will consume roughly 600 KB.

This happens because each pixel in a image is a vector4, with 4 values. So a 512x512 image is vector4 x 262 144.
Graphics and sound will be the largest consumers of memory.

3.) The nature of these systems, I have made a few, is that you will often uses classes.
Something like a item will be derived from a item class, with special item properties like use() that differs per item type.
The thing that goes into the list is this instance of the class. For example:

class Items():
  var name = ""

  #Godot makes constructors like python
  func _init(InName):
     self.name = InName

  func MyFunction():

Now you can use this class for all items.

var ListOfItems = [ Item.new("Apple"), Item.new("Sword")]

#Functions are called using the item
ListOfItems[0].MyFunction() #prints Apple
ListOfItems[1].MyFunction() #prints Sword

So even if you can’t drop a function into a list you can still call it from a class instance like normal.

You kinda can add a function to a list, but not really.

#This won't work
func PrintHello():
   print("hello world")
#This kinda works because of the return
func AddTwoNumbers(InA, InB):
   var MyResult= InA+InB
   return MyResult

var ListOfFunctions = [PrintHello(), AddTwoNumbers(1 ,10)]

print( ListOfFunctions [0])
print( ListOfFunctions [1])

Will return:

Hello World #Because the moment it was added to the list it ran the code
Null #The actual [0] slot is empty, so it is null
11 #The value that was returned actually went into the list

As far as I understand it, classes and dictionaries are very similar anyway, so a class would probably do the best job. Thank you for your input!

johnnywycliffe | 2018-10-04 04:30