Not sure what parameter to put for the level up function


Hey. So I tried making both a level and a level up function, which I thought would be simple enough. But it needs, or they both need another parameter. I put "self" on both. Every time I try playing it in game, it says "expected 1 parameter," or "expected 2 parameters."

The Pixie

You do not need any parameters here. Remove them from both functions and it should work.


let's first get the concept of a programming Function understood, using math (algebra):


Function: y = x + 4

Parameter (local/temporary VARIABLE): x
// this 'x' VARIABLE (and the value/input/argument it holds) only exists for Function 1. This 'x' variable for Function 1 can't be used in/for Function 2 directly

Argument (input): 7
// we need to give a value for our 'x' Parameter (local/temporary VARIABLE), which I chose '7' here for an example. The 'x' is a VARIABLE that will hold the given argument value/input, which is 7 in this case: x = 7

Return Type: integer // in quest: int

Return Expression: x + 4 // (x:7) + 4 = 11 // our 11 is an integer, which matches up with our specified Return Type: integer, so no error/confusion occurs

y: a VARIABLE to hold the Function 1's returned integer value (11)
// IMPORTANT: this 'y' actually is NOT part of Function_1 at all

here's how the Function looks, IN USE ('calling' a Function), as a programming Function, an example (using for the Object that holds its 'y' Attribute, the 'player' Player Object. This makes our 'y' VARIABLE, an Attribute VARIABLE, which is permanent/global in 'scope', it can be used anywhere, as it is attached-to/contained-within/held-by an Object, so long as of course that Object exists and/or still exists. Think of it like this: I am an Object and let's say I have the bubonic plague inside of me, that bubonic plague is an 'Attribute VARIABLE' of me, it exists so long as I exist, but when/if I die, then it dies too. Though, just like the bubonic plague, a global-'scope'/permanent Attribute VARIABLE or a local-'scope'/temporary Variable VARIABLE, can both be passed onto/into something else too):

player.y = Function_1 (7)
// Function's Parameter (local/temporary VARIABLE): x = 7
// Function's scripting/expression: x + 4
// Returned Value: 11 // (x:7) + 4 = 11
// player.y = 11

player.y = Function_1 (2)
// Function's Parameter (local/temporary VARIABLE): x = 2
// Function's scripting/expression: x + 4
// Returned Value: 6 // (x:2) + 4 = 6
// player.y = 6

player.y = Function_1 (99)
// Function's Parameter (local/temporary VARIABLE): x = 99
// Function's scripting/expression: x + 4
// Returned Value: 103 // (x:99) + 4 = 103
// player.y = 103


Function: z = x * 2

Parameter: x

Return Type: integer

Return Type's Scripting/expression: x * 2

Argument: 3

player.z = Function_2 (3)
// x = 3
// x * 2
// 6 // (x:3) * 2 = 6
// player.z = 6

player.z = Function_2 (6)
// x = 6
// x * 2
// 12 // (x:6) * 2 = 12
// player.z = 12

player.z = Function_2 (100)
// x = 100
// x * 2
// 200 // (x:100) * 2 = 200
// player.z = 200

the 'x' Parameter from/of Function_1 has nothing to do with Function_2
the 'x' Parameter from/of Function_2 has nothing to do with Function_1

notice how I had to use a different Attribute VARIABLE from: 'y, 'player.y', for Function_2: z, player.z

I did this so that I'm storing the returned value of Function_1 into: player.y, and I'm storing the returned value of Function_2 into: player.z

If I used 'player.y' for Function_2, an example:

player.y = Function_1 (7)
// Function_1: (x:7) + 4 = 11
// player.y = 11
player.y = Function_2 (3)
// Function_2: (x:3) * 2 = 6
// player.y = 6

you can see that I've lost my '11' value, as it is replaced by the '6', as I can use our 'player.y' Attribute VARIABLE for both Functions (it's not limited to just the Function_1 like our 'x' Parameter/Variable-VARIABLE is for Function_1, and our 'x' Parameter/Variable-VARIABLE for Function_2), because Attribute VARIABLES are global in scope, they can be used anywhere and as much as you want, but this means that their old values get replaced by new values

so, if I wanted to preserve that '11' value from Function_1, I used one Attribute for it: player.y, and another Attribute, player.z, to preserve the '6' value from Function_2

I can then do this:

player.m = player.y + player.z

and get:

// player.m = (player.y:11) + (player.z:6) = 11 + 6 = 17
player.m = 17

I now have '17' stored in my 3rd Attribute: player.m

with all that said, in programming, you do NOT have to have Parameters/Arguments and/or nor Return Types, they're both separately optional.

But if you do have Parameters (however many/quantity of them you want) in your Function definition, then you must have matching (same quantity of) Arguments (inputs for your Parameters) in your function's use ("call, calling a function"), or you'll get an error.

Function Definition (creation: "defining" its setup for what it: is, needs, and does) using my example functions above:

<function name="Function_1" parameters="x" type="int">
  return (x + 4)

<function name="Function_2" parameters="x" type="int">
  return (x * 2)

and then using ('calling') a function, examples:

player.y = Function_1 (7)
// player.y = (7+4) = 11

player.z = Function_2 (3)
// player.z = (3*2) = 6

player.k = Function_1 (9) + Function_2 (6)
// player.k = (9+4) + (6 *2) = 13 + 12 = 25

if your Function returns a value, you need to specify its Return Type (int, string, boolean, etc), and have your value's Type matchup with that specified Return Type: if you specify the Return Type as an 'int', quest/computer expects that returned value to be an 'int', and not as another type such as a 'string', for example:

<function name="Function_3" parameters="x" type="int">
  return (x + 8)

// player.w = Function_3 ("hi") ---> ERROR! As "hi" is a string value, which is used for the return value, but we've said the return value is suppose to an 'int' to quest/computer, so it'll return an ERROR to you

// --------------------

but, we can make this work for a string value (instead of an int) like this:

<function name="Function_3" parameters="x" type="string">
  return (x + "8")

// player.w = Function_3 ("hi")
// player.w = "hi8"

// string + string is calld "concatenation" which means literally putting next to each other: "hi" and "8" (this "8" is a string value as double quotes tell quest that it's a string type, and thus making it not an amount~number:int/double type value) are put next to each other, making: "hi8"

here's examples:


7 + 7 = 14
55 + 55 = 110
"hi" + "hi" = ERROR!
"hi" + 7 = ERROR!
7 + "hi" = ERRO!


"7" + "7" = "77"
"55" + "55" = "5555"
"hi" + "7" = "hi7"
"7" + "hi" = "7hi" or an ERROR (if it's used as a 'name', that's a "no no", as names can't start with a number), depends on how the programming is designed...
7 + 7 = ERROR!
"7" + 7 = ERROR!

anyways... back to a Function with a Return Type:

also, a returned value must be used/applied to something, you can't just have a Function with a Return Type by itself, as you then got a hanging value, that's not being used for anything

for example:

<function name="Function_4" parameters="x" type="int">
  return (x) // the most pointless/stupid function of all time, lol

Function_4 (2) ---> ERROR!

player.p = Function_4 (2) ----> NO error

msg ("your returned value is: " + Function_4)
// the 'msg' Script/Function is a built-in Function

player.g_as_a_string = ToString (Function_4 (2))
// the 'ToString' Script/Function is a built-in Function

here's examples of a Function with no Parameters/Arguments nor Return Type:

<function name="Function_50">
  msg ("hi")

<function name="Function_51">
  player.y = 20 // remember, Attribute VARIABLES (NAME_OF_OBJECT.NAME_OF_ATTRIBUTE) are global, they can be used anywhere, and their stored values are preserved (so long as the Object, in this case the 'player' Player Object, exists and/or still exists)

example of a Function with a Return Type, but no Parameters/Arguments:

<function name="Function_70" type="int">
  return (100)

player.y = Function_70 () // <--- in quest, the parenthesis may not be needed (when there's no Parameters/Arguments: when not using Parameters/Arguments), but many programming languages do require the parenthesis, even if no Arguments/Parameters, as the prenethesis is what tells the programming language/computer that it's a Function
// player.y = 100

examples of a Function with Arguments/Parameters, but no return type:

<function name="function_90" parameters="string_1, string_2, string_3">
  msg (string_1 + " " + string_2 + " " + string_3)

<function name="function_90" parameters="string_1, string_2, string_3">
  player.my_string = string_1 + " " + string_2 + " " + string_3

lastly, transfering (passing) and thus indirectly using Parameters (local/temporary VARIABLES) from one Function to another Function, exmaples:

<function name="Funtion_100" parameters="x">
  Function_101 (x)

<function name="Function_101" parameters="y">
  msg (y)

Function_100 ("hi")
// result: hi
// what/how this result occurred:
// Function_100: x = "hi"
// Function_101: y = x // x = "hi" // y = x = "hi" ---> y = "hi" ---> msg (y) // msg ("hi") ---> result (output/displayment): hi

you can use different names for Parameters or the same (sometimes it's better to use different names and sometimes it's better to use the same names, it depends on what you're doing), it doesn't matter, only the position of the Parameters/Arguments matter, for example, this does the exact same thing as above:

<function name="Funtion_100" parameters="x">
  Function_101 (x)

<function name="Function_101" parameters="x">
  msg (x)

Function_100 ("hi")
// result: hi
// what/how this result occurred:
// Function_100: x (of Function_1) = "hi"
// Function_101: y = x (of Function_2) // x (of Function_1) = "hi" // x (of Function_2) = x (of Function_1) = "hi" ---> x (of Function_2) = "hi" ---> msg ( x {of Function 2} ) // msg ("hi") ---> result (output/displayment): hi

this is because Parameters are local/temporary Variable VARIABLES, the 'x' Parameter of Function_1 has no bearing on the 'x' Parameter of Function_2, but we're storing the value held by Function_1's 'x' into the 'x' of Function_2, so in this way we're indirectly using the 'x' Parameter of Function_1 outside of Function_1, but not directly/technically so, as we're storing it into Function_2's 'x' Parameter for its use in Function_2, the 'x' Parameter of Function_1 is not as it can not be used outside of Function_1, but we can store it's value into Parameters of other Functions, and thus we're "transfering" one Function's Parameters' values to another Function's Parameters

// -------------


you can NOT do this (as we're trying to use a Parameter directly from one Function into another Function, which we can NOT do, as Parameters are 'local/temporary', they only exist within their Function, as that's the limit of their 'scope', their 'scope' is local, which is to the Function that holds/has that Parameter):

<function name="Funtion_100" parameters="x">

<function name="Function_101">
  msg (x)

Function_101 ("hi")
// ERROR! the 'x' Parameter in Function_2 was never given a value, hence the ERROR!

the 'x=100' for Function_100 only exists in Function_100, that's why the 'x' in Function_2 doesn't have a value. The 'x' in Function_2 is a separate VARIABLE from the 'x' in Function_1.

whereas, with Attributes, its a single VARIABLE, as it's global in scope, which is why you can use it anywhere, it's not one Attribute used in one place and a different Attribute used in another place. That Attribute (IDENTIFIED by its name) is that Attribute, just as my DNA identifies me as me and only me, and your DNA identifies you as you and only you.

this is NOT the case with Variable VARIABLES (such as Parameters), in terms of outside of their scope. I can have an 'x' Parameter in one Function and also an 'x' Parameter in another Function, as these are two different 'x' Parameters (due to scope: outside of their scope). But, I can NOT have two (different) 'x' Parameters in the same Function (due to scope: inside of their scope).

an Attribute VARIABLE's scope is global, the entire game code, that is why I can only have one and only one, for example, 'player.x' Attribute, I can't have another 'player.x' Attribute. I can have 'player.x' Attribute and 'game.x' Attribute, as while the Attribute name is the same (x), they belong to different Objects: 'player' vs 'game', which makes them different Attributes, as an Attribute is: NAME_OF_OBJECT.NAME_OF_ATTRIBUTE

for example in the real world:

let's take 'water' and 'sand'

an 'attribute' of water is that it is 'wet'
an 'attribute' of sand is that it is 'dry'

water.wet is a unique attribute of water
sand.dry is a unique attribute of sand

well, we know that sand can become wet too:


but this is perfectly okay: wet water and wet sand, can most certainly exist at the same time, we're not getting into quantum mechanics, these are two different attributes, even though they're both the same 'wet' attribute. This is because that's what an attribute is, it's an "adjective/adverb' of some noun, an attribute is describing something, an attribute is a property/characteristic/trait of something, that's why you can have joe with the 'freckles' attribute and sarah with the 'freckles' attribute.

a Variable (Variable VARIABLE, such as a Parameter) however is not describing something, it's just a variable holding a value, so you can only have one 'wet' Variable.

and that's it for now... see if this makes sense and helps you understand what you're doing in the GUI/Editor, and if not, let me know, and I'll help you more specifically with how to do Functions in the GUI/Editor


oh, forgot one thing:

an Argument can either be a "literal" (direct value) or a VARIABLE (a Variable VARIABLE or an Attribute VARIABLE):

Function_200 (4) // literal/direct value
// or:
v = 4
Function_200 (v) // a Variable VARIABLE
// or:
player.v = 4
Function_200 (player.v) // an Attribute VARIABLE



if you want a 'level up' system/code/functionality (as in you choose what stats/etc to raise at a level up), you can use Pixie's 'level lib' or whatever it's current form is in his 'combat library version=?'. This is really complicated stuff with concatenation of Commands... not easy to do and especially figure out on your own (unless you're already a good programmer, lol). Took me forever to just understand it, laughs.

and if you're interested, here's leveling function that I like:

<function name="leveling_function">
    if (player.experience >= player.level * 100 + 100) {
      player.experience = player.experience - (player.level * 100 + 100)
      player.level = player.level + 1

starting/initial level of player: 0 // or 1 (but you'd need to jump over the line below, obviously)
exp needed for levelup: (player.level:1) * 100 + 100 = 0 + 100 = 100
(take away 100 experience from the player's current experience, as that was used to level up)
player level: 1
exp needed for levelup: (player.level:1) * 100 + 100 = 100 + 100 = 200
(take away 200 experience from the player's current experience, as that was used to level up)
player level: 2
exp needed for levelup: (player.level:2) * 100 + 100 = 200 + 100 = 300
(take away 300 experience from the player's current experience, as that was used to level up)
player level: 3
etc etc etc etc

so, here's some examples, using starting at level 0 to make it easiest to understand:

player.level = 0
player.experience = 0
(you kill a monster and get 100 exp)
player.level = 1
player.experience = 0 // need 200 for lvlup, need full 200 more exp

player.level = 0
player.experience = 0
(you kill a monster and get 200 exp)
player.level = 1
player.experience = 100 // need 200 for levelup, only need 100 more exp

player.level = 0
player.experience = 0
(you kill a monster and get 300 exp)
player.level = 2
player.experience = 0 // need 300 for level up, need full 300 more exp

player.level = 0
player.experience = 0
(you kill a monster and get 400 exp)
player.level = 2
player.experience = 100 // need 300 for level up, need only 200 more exp

player.level = 0
player.experience = 0
(you kill a monster and get 500 exp)
player.level = 2
player.experience = 200 // need 300 for level up, need only 100 more exp

player.level = 0
player.experience = 0
(you kill a monster and get 600 exp)
player.level = 3
player.experience = 0 // need 400 for level up, need full 400 more exp

etc etc etc


oops, forgot one last thing about Functions:

Arguments and Parameters must match up (if you've got multiple Args/Params: more than 1 Arg/Param):

Arg_1 <---> Param_1
Arg_2 <---> Param_2
Arg_3 <---> Param_3

this is done/determined by POSITION, (and NOT their names: such as if using/passing/transfering one Function's Parameter/s to another Function's Parameter/s):

<function name="example_function" parameters="pos_1_param, pos_2_param, pos_3_param, etc etc etc">

example_function (pos_1_arg, pos_2_arg, pos_3_arg, etc etc etc)

// this is how they are matched up, so make sure that they do match up correctly:
pos_1_arg ---> pos_1_param
pos_2_arg ---> pos_2_param
pos_3_arg ---> pos_3_param
etc etc arg ---> etc etc param


Good grief, HK. You trying to scare him away xD ?? Look at that block of code! laughs



(I wonder how many people really read all of that...)
Just use the coding that DnD uses...
if (player.XP>2000 and player.level=1){
else if (player.XP>4000 and player.level=2) {
and so on...
or, you could add a check on class/ XP level...
or... compare the player to a split...
player.class.fighter = Split(" 0,2000,4000,8000,16000,32000", ",")
if (player.xp>player.class.fighter(player.level)){
msg("You gained a level and are now level {player.level}!!!")
msg("Now you only need {player.class.fighter(player.level)} - {player.xp} experience to make your next level.")

(Yes, I may have a bug there, but you should get the idea...)
and the output should look like...
You gained a level and are now level 2!!!
Now you only need 1950 experience to make your next level.

Log in to post a reply.