Giter Club home page Giter Club logo

Comments (11)

Myonmu avatar Myonmu commented on June 2, 2024 1

Fixed and pushed. @smwhr

The lua side external function only takes a table as its first parameter, you will need to get your desired value from the table.

For example:

function addPhonebook(args) 
    local name = args[1]
    local number = args[2]
end

from tinta.

Myonmu avatar Myonmu commented on June 2, 2024 1

I tested the same ink with C# and tinta doesn't have the same behaviour. I'll have to look deeper into it. This can be tricky to debug though.

from tinta.

Myonmu avatar Myonmu commented on June 2, 2024 1

Now it should work. The default behaviour is now not look ahead safe when binding a function (so you don't need to pass the third parameter when binding). When it is look ahead safe, it will still be invoked twice which is the same behaviour as the C# version.

from tinta.

ZeAntwan avatar ZeAntwan commented on June 2, 2024 1

All working on my end too! Thanks for these quick fixes!
I might run into other issue, but I'll make a new one to avoid changing this one too much over time for posterity 😁
And I'll make sure to check against ink documentation to see if what I'm noticing is a bug or a feature I need to add on my end

I'll let you close it whenever you feel is right (probably once the merge has been accepted)

from tinta.

smwhr avatar smwhr commented on June 2, 2024

Pinging @Myonmu !

from tinta.

ZeAntwan avatar ZeAntwan commented on June 2, 2024

Amazing! I tried that fix and now the function gets called, thanks for the added instructions!

However, another issue I ran into was that the function gets trigger twice now. In the test project i get this when ran:

Emergency
Loop 1
Emergency
Loop 2

Is that expected?

from tinta.

Myonmu avatar Myonmu commented on June 2, 2024

Amazing! I tried that fix and now the function gets called, thanks for the added instructions!

However, another issue I ran into was that the function gets trigger twice now. In the test project i get this when ran:

Emergency
Loop 1
Emergency
Loop 2

Is that expected?

Hmmm, I did noticed that under some circumstances the function can be called twice, but in my case it was an ill-written ink. What ink are you using that produced this result?

from tinta.

ZeAntwan avatar ZeAntwan commented on June 2, 2024

Exactly the same as my initial post, no change. Let me send you the zip of the ink, json and lua export I've got
tinta.zip

from tinta.

smwhr avatar smwhr commented on June 2, 2024

IIRC, that's expected, the engine sometimes execute some part of ink twice ("lookAhead") to deal with newlines and glue.
The original code has a lookAheadSafe parameter to deal with that.

from tinta.

ZeAntwan avatar ZeAntwan commented on June 2, 2024

Yes, I've been exploring the code a bit, and saw that complete comment next to the function at line 1183 of the story.lua file, meaning that, if I understood correctly, if I want that function to be only executed once, I should set the last argument to that Binding function to false

---Bind a lua function to an ink EXTERNAL function declaration.
---@param funcName string EXTERNAL ink function name to bind to.
---@param func function The lua function to bind.
---@param lookaheadSafe boolean the ink engine often evaluates further
---than you might expect beyond the current line just in case it sees 
---glue that will cause the two lines to become one. In this case it's 
---possible that a function can appear to be called twice instead of 
---just once, and earlier than you expect. If it's safe for your 
---function to be called in this way (since the result and side effect 
---of the function will not change), then you can pass 'true'. 
---Usually, you want to pass 'false', especially if you want some action 
---to be performed in game code when this function is called.
function Story:BindExternalFunction(funcName, func, lookaheadSafe)

But I then instead run into this error for which I'll try the suggested workaround

error("External function "..funcName.." could not be called because 1) it wasn't marked as lookaheadSafe when BindExternalFunction was called and 2) the story is in the middle of string generation, either because choice text is being generated, or because you have ink like \"hello {func()}\". You can work around this by generating the result of your function into a temporary variable before the string or choice gets generated: ~ temp x = "..funcName.."()")

Although it feels like my case doesn't match what the error describes here

from tinta.

smwhr avatar smwhr commented on June 2, 2024

Merged and closing !
Thank you for everything !

from tinta.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.