How to make a function change the object that called it?

plospo
01 Jun 2014, 11:03
Hello!
I'm a new user, as indicated by my amount of posts, but so far my learning curve has been pretty smooth and I'm having lots of fun.

Now to the question: I'm trying to make a function that changes the object attribute of the object it's called from. For example, when you "bash" an object, it calls the "break" function which changes the attribute of the object to "broken".

...But when the object verb calls the function, how do I make the function know that it's supposed to change the attribute of THAT particular object? Having it change the attribute of a specific object is easy, then I just type in the name in the "Set object's attribute" command.

That very same command also features an "expression" tab, instead of "name", where I figure I'll have to type something to make it change the attribute of ANY object it's called from. But what is the syntax for that!? :?

If this is an easy answered question, that perhaps have already been answered in another post, then forgive a noob and please give me a link :) I've googled enough for today.

This would save me sooooo much time not having to copy-paste stuff for each individual object. Thanks in advance!

jaynabonne
01 Jun 2014, 13:39
You use "this" to refer to the object that the verb has been called on. So to set "broken" you'd use "this.broken".

plospo
01 Jun 2014, 16:42
Woah, that was easy... heh how embarassing.
But thanks a lot!

jaynabonne
01 Jun 2014, 16:54
It's easy when you know it. :) No need for embarrassment.

HegemonKhan
02 Jun 2014, 01:34
also, you can use the 'parameters' attribute for functions too, an example:

<command name="show_character_information_command">
-> <pattern>showcharinfo #object#</pattern>
-> <script>
->-> // what you type in during game play = #object# = (object)
->-> show_character_information_function (object)
-> </script>
</command>

// (object) = "object_x"

<function name="show_character_information_function" parameters="object_x">
-> ClearScreen
-> msg (object_x.alias)
-> msg (object_x.gender_string)
-> msg (object_x.race_string)
-> msg (object_x.class_string)
-> wait {
->-> ClearScreen
-> }
</function>

for examples:

player1.alias = "HK"
player1.gender_string = "male"
player1.race_string = "human"
player1.class_string = "warrior"

player2.alias = "plospo"
player2.gender_string = "male" // or "female" ~ I don't know, lol
player2.race_string = "human"
player2.class_string = "wizard" // just pretend you want to be a wizard character, only for example

if you type in:

showcharinfo player1

outputs:

HK
male
human
warrior

if you type in:

showcharinfo player2

plospo
male // or female
human
wizard // or whatever class you want to be

--------

and you can go as deep in layers as you want:

player1, player2

function1 (HK,plospo)
-> function2 (me,you)
->-> function3 (self,enemy)

the object being used remains the same, regardless of what you name~label each parameter item, by POSITION:

function (parameters' POSITIONS: 1,2,3,etc)

player1 = HK = me = self
player2 = plospo = you = enemy

OR, you can use the same labels too for all the parameters:

function1 (player1,player2)
-> function2 (player1,player2)
->-> function3 (player1,player2)

or

function1 (red,blue)
-> function2 (red,blue)
->-> function3 (red,blue)

will still use the exact same objects (player1 and player2) as:

function1 (HK,plospo)
-> function2 (me,you)
->-> function3 (self,enemy)

--------------

I forgot to show exactly how parameters work though within the function itself:

player1,player2

// player1 = HK
// player2 = plospo

function1 (HK,plospo)
-> if (HK.speed > plospo.speed) {
->-> function2 (me,you)
->-> // player1 = HK = me
->-> // player2 = plospo = you
-> } else if (HK.speed < plospo.speed) {
->-> function2 (you,me)
->-> // player1 = HK = you
->-> // player2 = plospo = me
-> }

---------

// player1 = HK = me = self
// player2 = plospo = you = enemy

function2 (self,enemy)
-> enemy.hp = enemy.hp - self.damage
-> // player2.hp = player2.hp - player1.damage

~OR~

player1 = HK = you = enemy
player2 = plospo = me = self

function2 (enemy,self)
-> enemy.hp = enemy.hp - self.damage
-> // player1.hp = player1.hp - player2.damage