Are you able to use functions to wrap data in?

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

I am wondering if its possible to wrap data in functions.

Example:

func NewCategory(cateogry):
	# set array to category
	# set data in between to new class

func EndCategory():
	# end the category here

NewCategory("Stock Faction")
	NewClass("Wanderer")
	NewClass("Another Class")
EndCategory()

This would then output an dictionary like this

var categorys = {"Stock Faction": ["Wanderer", "Another Class"]}

Any reason you don’t simply do the following?

categories = {}
categories["Stock Faction"] = []
categories["Stock Faction"].append("Wanderer")
categories["Stock Faction"].append("Another Class")

njamster | 2020-07-29 14:22

There is more data that each class has but I will probably just end up doing it that way. I had made the second argument be the category but didn’t want to have to have to define the category for each class and instead just have it put them in correct category.

Walrusking | 2020-07-30 01:49

Didn’t want to have to have to define the category for each class

You could do it like this:

var categories = {}
var category = []
category.append("Wanderer")
category.append("Another Class")
categories["Stock Faction"] = category

njamster | 2020-07-30 19:06

Yes that will work perfectly, thank you. I’m not sure how to mark this as answered.

Walrusking | 2020-07-30 19:09

I’m not sure how to mark this as answered.

You cannot choose a best answer as there are no answer yet. I only left a comment as wasn’t sure I fully understood your problem. I re-posted my comment as an answer, so now you should be able to mark this as the best answer if you want. :slight_smile:

njamster | 2020-08-01 17:40

:bust_in_silhouette: Reply From: njamster

You could do it like this:

var categories = {}
var category = []
category.append("Wanderer")
category.append("Another Class")
categories["Stock Faction"] = category