Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best Practice for Functions that utilize List Items as Parameters? #80

Open
Bard09 opened this issue Jan 30, 2024 · 0 comments
Open

Best Practice for Functions that utilize List Items as Parameters? #80

Bard09 opened this issue Jan 30, 2024 · 0 comments

Comments

@Bard09
Copy link

Bard09 commented Jan 30, 2024

[NOTE: Using the Godot4 Branch]

I have many different native functions in Ink that use List parameters... so I when I rolled out inkgd I wanted to make sure those worked in particular. One of my concerns was that I didn't want to have to generate a 'fresh' parameter every time I queried these functions, as I know performance can be an issue. So here's what I did... I'm curious if you have any suggestions for improvement?

I ended up creating a local Dictionary that I could call with the item name only (I don't reuse items names between lists), and it'd return a cached formatted InkList with a Single Item that I could pass as a parameter to the function. It looks something like this:

        #Creating a Godot Dictionary & populating it with List parameters from 1 list called "fields"
        var listItems: Dictionary
	var fields: InkList = story.get_variable("fields")
	for each_field: InkListItem in fields.all.keys(): 
		listItems[each_field.item_name] = InkList.new_with_single_item(InkListItem.new_with_full_name(each_field.full_name), 0)

        #Example Function Call that returns a string response
        var resultText: String = story.evaluate_function("exampleFunction", [listItems[each_field.item_name]]).return_value

Is this the 'best' way to accomplish this goal? I ultimately wrote a wrapper function for some of this but wanted to see if there was an alternative recommendation for what I was trying to do.

Additionally.... I have 20-30 lists I'd have to loop through in this manner to cache them in the Dictionary. I think it's technically possible to use InkStory and get the lists via ListDefinitions as an alternative-- but to get that to work you'd have to be using InkStory, not the InkPlayer-- correct? There's no way to loop through all the ListDefinitions otherwise? Just want to confirm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant