|
|
|
|
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():
print(name)
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