Skip to content

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

Description

@Bard09

[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 :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions