Function Calling Script Attribute from Target [SOLVED, TY!]

Hey all!

So I have a Function that gets called from an enemy that's part of an enemy_type group during a particular scenario. On that Function, I have parameters as "target" and "object" to reference the current enemy.

I was wondering if it was possible for that Function to call back to that specific enemy_type for an attribute to fire/proc under a certain circumstance. Would it be something like...

target.specificscriptnamehere = Print <--- I know that isn't right but I'm not sure how to do it.
Script gets printed during the function.

Am I making sense or talking crazy talk. Here's what I mean.

Female_Zombie_Type
Attribute
SpecificScriptNameHere Script

During a fight with a Female Zombie, certain scenario procs the Function. 

During the Function, I need that SpecificScriptNameHere script to Print from the zombie_type enemy/female zombie object. 

Anonynn.


I'm not sure I understand you right.

You want a function to run a script attribute on an object passed to it as a parameter?
Like do (target, "scriptname")?

Or something more complex that I'm missing?


to do/use/fire/proc/activate within scripting:


Functions (with a return type or not):

NAME_OF_FUNCTION
or
NAME_OF_FUNCTION (ARGUMENTS/PARAMETERS)


Script Attributes (no return type and no custom arguments/parameters):

do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE")
or
do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE", DICTIONARY_VARIABLE_AS_THE_ARGUMENT/PARAMETER)

or

// (the 'invoke' is more limited than 'do', as 'invoke' uses dot notation scripting, so no dynamic usage like can be done with 'do')

invoke (NAME_OF_OBJECT.NAME_OF_SCRIPT_ATTRIBUTE)
or
invoke (NAME_OF_OBJECT.NAME_OF_SCRIPT_ATTRIBUTE, DICTIONARY_VARIABLE_AS_THE_ARGUMENT/PARAMETER)


Delegates + Script_Attributes (able to have custom arguments/parameters and/or a return type):

// (Delegates+Script_Attributes is basically a localized/attached-to-object/contained-within-an-object Function)

// with no return type:
rundelegate (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE", ARGUMENTS/PARAMETERS)

// with a return type:
RunDelegateFunction (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE", ARGUMENTS/PARAMETERS)


if you just want to print something, you can just have it be a String Attribute (unless you need to do concatenation or whatever), instead of as a Script Attribute

here's examples of some of the various methods:

<game name="EXAMPLE">

  <attr name="start" type="script">
    msg (female_zombie.appearance_string_attribute)
    // or
    invoke (female_zombie.appearance_script_attribute)
    // or
    do (female_zombie, "appearance_script_attribute")
  </attr>

</game>

<object name="female_zombie">
  <inherit name="female_zombie_type" />
</object>

<type name="female_zombie_type">

  <attr name="appearance_string_attribute" type="string">APPEARANCE</attr>

  <attr name="appearance_script_attribute" type="script">
    msg ("APPEARANCE")
    // or
    // invoke (female_zombie.appearance_script_attribute)
    // or
    // do (female_zombie, "appearance_script_attribute")
  </attr>

</type>

do (target, "scriptname")

^ that sounds correct and like it would work but I'm not sure.

It's to have a Function call a script attribute from an enemy_type of an enemy object

LOL

It's not as complicated as I'm making it sound. I have an enemy object that is part of a enemy_type. The script is on the enemy_type and I want the Function to fire it under a specific circumstance. Is that better?

If ... do (target, "scriptname") might work I can try it.

Hey HK :) I know how to do all with the firing in normal scripting but I don't know how to do it in reverse essentially. I explained it in the small blurb above xD

Anonynn.


<game name="EXAMPLE">
  <attr name="start" type="script">
    example_function (female_zombie.appearance_script_attribute)
    example_function (female_zombie.appearance_string_attribute)
  </attr>
</game>

<object name="female_zombie">
  <inherit name="female_zombie_type" />
</object>

<type name="female_zombie_type">

  <attr name="appearance_string_attribute" type="string">APPEARANCE</attr>

  <attr name="appearance_script_attribute" type="script">
    msg ("APPEARANCE")
    msg (this.appearance_string_attribute)
  </attr>

</type>

<function name="example_function" parameters="attribute_parameter">

  attribute_type_string_variable = TypeOf (attribute_parameter)

  if (attribute_type_string_variable = "string") {
    msg (attribute_parameter)
  } else if (attribute_type_string_variable = "script") {
    invoke (attribute_parameter)
  } else {
    msg ("ERROR")
  }

</function>

So you're saying I should add an attribute parameter to the Function? For example...
target
object
attribute

and then make the script on the zombie_type as a script and have an if-script on the Function invoke it?

if (attribute_type_string_variable = "script") {
invoke (attribute_parameter)
}

?

Anonynn.


So you're saying I should add an attribute parameter to the Function?

I don't see any reason that should be a parameter to the function.

HK's last function is designed to look at a variable, print it if it's a string, and run it if it's a script.
This might sometimes be useful; for example if different objects have a different type of attribute.

If the attribute can have multiple types, it's better to use TypeOf() than to store the type separately. If it's always the same type, you can just use 'do'.


Hey Mr.Angel :D

I have multiple types, for example...
female_zombie_type
male_zombie_type
male_minotaur_type etc

So I should do...

TypeOf (target, "scriptname") ?

Anonynn.


@HK

// (the 'invoke' is more limited than 'do', as 'invoke' uses dot notation scripting, so no dynamic usage like can be done with 'do')

Not relevant to the OP, I just feel obliged to correct incorrect information

Not quite. 'do' is more limited because it can only be used on scripts that are attributes.

You could in fact replicate the behaviour of 'do' using 'invoke'; but you can't do the opposite

<function name="custom_do" parameters="object, attribute_name, parameters">
  if (HasScript (object, attribute_name)) {
    script = GetAttribute(object, attribute_name)
    if (parameters = null) {
      parameters = NewObjectDictionary()
    }
    if (DictionaryContains (parameters, "this")) {
      dictionary remove (parameters, "this")
    }
    dictionary add (parameters, "this", object)
    invoke (script, parameters)
  }
  else {
    error ("No such script attribute: "+object.name+"."+attribute_name)
  }
</function>

(Note: I'd never recommend actually doing this; as it's just replicating the functionality of the built-in function do. But it's a demonstration that 'do' is a special case of 'invoke', and therefore more limited)


So I should do...

Are the attributes the same type?

You only need use TypeOf() if, for example, female_zombie_type.attributename is a script you want to run, but male_minotaur_type.attributename is a string you want to print.

This is how Quest does things like the look attribute, which can either be a string description or a script.

If the attribute is always a script, you can just use do.


Yeah they will all have the same attribute name. For example...

female_zombie_type.specialattribute
male_zombie_type.specialattribute
male_minotaur_type.specialattribute

all scripts which will run on the specific enemies when fired from the Function.

Anonynn.


I think then you can just do:

  do (target, "specialattribute")

(filler for getting my edited post, updated/posted)


@ Anonynn:

the 'Object Types / Types / Inherited Attributes' merely add those Attributes to the Object that you give the 'Object Types / Types / Inherited Attributes' to:

<object name="player">
  <attr name="example_script" type="script">
    msg ("EXAMPLE")
  </attr>
</object>

// is the exact same as:

<object name="player">
  <inherit name="example_type" />
</object>

<type name="example_type">
  <attr name="example_script" type="script">
    msg ("EXAMPLE")
  </attr>
</type>

so, what this means is that, for this example, CORRECT:

do (player, "example_script")
invoke (player.example_script)

<game name="EXAMPLE">
  <attr name="start" type="script">
    do (zombie_1, "example_script")
    invoke (zombie_1.example_script)
    do (zombie_2, "example_script")
    invoke (zombie_2.example_script)
  </attr>
</game>

<object name="zombie_1">
  <inherit name="female_zombie_type" />
</object>

<object name="zombie_2">
  <inherit name="male_zombie_type" />
</object>

<type name="male_zombie_type">
  <attr name="example_script" type="script">
    msg ("MALE")
  </attr>
</type>

<type name="female_zombie_type">
  <attr name="example_script" type="script">
    msg ("FEMALE")
  </attr>
</type>

whereas... WRONG:

do (example_type, "example_script")
do (player.example_type, "example_script")
invoke (example_type.example_script)
invoke (player.example_type.example_script)

invoke (female_zombie_type.specialattribute)
invoke (male_zombie_type.specialattribute)
invoke (male_minotaur_type.specialattribute)

do (female_zombie_type, "specialattribute")
do (male_zombie_type, "specialattribute")
do (male_minotaur_type, "specialattribute")

do (female_zombie_type, specialattribute)
do (male_zombie_type, specialattribute)
do (male_minotaur_type, specialattribute)


Thanks HK and Mr.Angel! I appreciate all of your time in helping me figure that out! If you two need anything lemme know!

This works...

do (target, "whatever_attribute")

As long as "target" is part of the Function's parameters.

Anonynn.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums