Forum rules - please read before posting.

How to interact with script? Variables and methods.

edited July 2016 in Technical Q&A
Hello. I'm new to AC. I've checked the forum and manual, but I didn't find a full answer to my question. How to interact with a custom script? There are two important questions to me:
1) How do I pass parameters to a custom method from an action list? I know I can call an event or send a message to call a method, but it only allows me to pass int parameters. Do I have to write a custom action to pass a bool variable?
2) How do I read public variables from my script? For example I have a Door script, that handles all of the stuff happennig when a player interacts with a door. Now I want to check public bool myDoor.isOpen from the action list. How do I do that?

Comments

  • Welcome to the forum, @GallopingDino.

    1) If you're just looking to pass a boolean, you could try sending "1" in place of True and "0" in place of False, and modifying the custom script to accept that as an alternative.

    Another way, which would also allow for a wider range of variable types, would be to set a Global (game-wide) or Local (per-scene) variable before calling the function, and then having the custom script read that variable's value.  Examples on reading and writing variables are found on the front page of the scripting guide and in Section 12.7 of the Manual.

    2) You could write a custom Action that checks the value of your variable, but again it's probably easier to send the variable's value to either AC's Global or Local variables as an interim and check from there using the Variable: Check Action.
  • edited July 2016
    Kudos to reading AC global variables (and writing to them). That's my favorite method, that way you can easily change settings in the variables manager or at runtime using Variable: set, without ever needing to touch your scripts again. Also, you can use any variable type and It's perfect for tweaking formulas and other "settings" you may have in your scripts. Specially useful if you create your own AC actions.

    I must say, before, I was hesitant to make my own actions, but now that I've learned how, I don't think I could live without them. Nothing beats condensing a complex string of actions or code into a simple and easy to use action ;)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.