How do I make use of functions properly?

0 favourites
  • 7 posts
  • So I'm trying to set up a text box / dialog system for my game. My initial idea was to use a function to pass the dictionary to load and the text to pull from it.

    However, Construct's functions seem unable to do this, as they prevent you from using even a single Trigger event in a function.

    This seems to kneecap the entire point of functions, being able to reuse your code. If the vast majority of useful logic that's the building blocks of making complex systems that you'd actually want to reuse at multiple points can't even be handled with C3's Functions, what's even the point?

    Am I missing something obvious here? Cuz it seems like I have to be. There's no way they can actually be this limited, right?

  • You call the function after the event has happened

    It's on tween finished : call function (with the relevant information as parameters)

    Inside the function / on function : do the actions

    So you might want to call the function with the dictionary item as a parameter and then inside the function it runs typewriter text with dictionary.get"param". It's reusable code where you want to run typewriter text with specific text stored as dict when a similar thing happens over and over i.e. tween finished, without making loads of separate events.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The gif was just an example. My main issue is that I have systems that I'll be reusing constantly like the dialog boxes and a stage introduction that contain multiple Trigger conditions. These are the kinds of things most primed to be used as functions, but it seems to not be possible in C3 due to Trigger events conflicting with Functions.

  • It's possible because you don't put the trigger condition inside the function. The condition occurs then you call the function based on this being true, and using the object picked in the condition you can also run parameters through the function such as text that could be an instance variable on the object. Think about the part you are going to be reusing, that should be inside the function. If that doesn't help you'll have to post the exact events of what you are trying to do because the previous post was quite vague.

  • It doesn't make sense to put a trigger in a function. Triggers only run when some outside event happens, like a mouse click. Functions only run when you use a 'call function' action. There is no overlap between these. Since it's invalid, the editor disallows it.

    I think you need to just rearrange the events so you call the function in the triggered event.

    Perhaps you are confusing functions with libraries - they're two different cases. A function is a single re-usable piece of logic, and a library is a collection of functions and other pieces of logic. Right now Construct doesn't have a good equivalent for libraries, but functions work analogously to how they do in programming languages.

  • It makes sense for something like a mouse click, but what about when a tween finishes? I have a series of graphics tweening in sequence that make up a stage intro. Ideally I'd like all of that to be a function, but because of all the triggered tweens I can't do that. I've worked around it but putting them all into a group and toggling it on and off as needed, but you have no way of passing parameters that way, so for my system I'm trying to build for calling dialog boxes, which I wanted to pass parameters to determine which text to pull from an array or dictionary, I'm kinda out of luck unless I make every triggered event it's own function, then have a master function that starts the chain of calling each one in sequence to make the entire thing work.

    I am probably just too new at traditional programming to understand the stupidity of what I'm asking, but just as a lay person, it is kinda frustrating to try and find ways to work around things like this, even if it makes sense that it wouldn't work considering the linear nature C3 reads event sheets.

    Is it possible to create a function with parameters, then have that function run a JS script that can reference those parameters? That was a method I was interested in trying next, mixing events with traditional scripting.

    Either way, thanks for the response and the patience with my limited understanding of how C3 works under the hood ^_^;;

  • You can list all the tweens as actions in order against a global variable condition, so first tween is gv=1, second tween settings are gv=2, with a trigger once condition.

    Then you say on tween ended, add 1 to gv.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)