+1 vote

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.

in Engine by (24 points)

1 Answer

+1 vote

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
by (1,434 points)
edited by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.