Function call

tvisarl
13 Jul 2016, 09:48

It is a noob question, but as I can't search the forum...

What is the syntax for calling a function that returns a value but has no parameters?

Thanks,
Thierry


bergedorfcacher
13 Jul 2016, 10:31

Try this:
yourresult = YourFunction()


tvisarl
13 Jul 2016, 10:36

Sorry, this doesn't work, at least for me. Quest answers that there can be no null parameters. By the way, the "null parameter" is called "key".
Ok, I know, I could update a global variable, but "my" solution would be more elegant.


Pertex
13 Jul 2016, 10:59

This message appears if you haven't defined a return type in your function


Jay Nabonne
13 Jul 2016, 11:12

Also, parens are optional if there are no arguments. So

x = Myfunction()

or

x = MyFunction

But it sounds like what Pertex said. :)


hegemonkhan
13 Jul 2016, 11:50

in code:

http://docs.textadventures.co.uk/quest/elements/function.html

// defining (setting up) the Function (with NO Parameters but it DOES RETURN a Value):

<function name="NAME_OF_YOUR_FUNCTION" type="THE_RETURN_ATTRIBUTE_TYPE">
  // whatever scripting
  return (YOUR_VALUE_WHICH_MUST_MATCH_UP_WITH_YOUR_SET_RETURN_TYPE_IN_THE_FUNCTION'S_HEADER_ABOVE)
</function>

// calling the Function (and setting it's RETURN Value to be stored in a VARIABLE --- you MUST do something with the RETURNED VALUE, storing it in a VARIABLE or having another script use it, else you'll get an ERROR!):

VARIABLE = NAME_OF_YOUR_FUNCTION

in the GUI~Editor:

// defining the Function:

Function -> Add -> Name: NAME_OF_YOUR_FUNCTION

NAME_OF_YOUR_FUNCTION -> 'whatever' Tab -> there should be options for having it return a value and setting its attribute type

// calling the Function:

'whatever' Element -> run as script -> add new script -> 'variables' section/category -> 'set a variable or an attribute' Script -> [EXPRESSION] -> set variable YOUR_VARIABLE = [EXPRESSION] NAME_OF_YOUR_FUNCTION


tvisarl
13 Jul 2016, 12:03

Aaah, that's it ! Thanks to you all. But it seems that parens aren't optional, which is logical for me.


The Pixie
13 Jul 2016, 13:48

Parentheses are optional when the function is on its own. So

MyFunction

But

x = MyFunction()
msg(MyFunction())

hegemonkhan
13 Jul 2016, 16:06

Ah, thank you for clarifying up when parenthesis are needed vs not/optionally, Pixie!