Use attributes as parameters in a new function

josaaku
Hi!

First of all: I love this engine, it was exactly what I was looking for!

Second: If my question has been answered elsewhere, I just didn't find it.

This is the problem:

I have an object, called Bob. This object has an attribute, called agility as integer.

I need a function to do "return a random Int between 1 and THAT attribute of THIS object."

So i tried:
  
<function name="rollattribute" parameters="object, trait">
msg (GetRandomInt(1,object.trait))
</function>


When calling rollattribute (Bob, "agility") it returns
Error running script: Error compiling expression 'GetRandomInt(1,object.trait)': FunctionCallElement: Could find not function 'GetRandomInt(Int32; Object)'

When calling rollattribute (Bob, agility) it returns
Error running script: Error compiling expression 'agility': Unknown object or variable 'agility'

Nice little fact: A function to roll a fixed stat for THAT object works perfectly well.

<function name="rollagility" parameters="object">
msg (GetRandomInt(1,object.agility))
</function>


everything is fine with that, i can rollagility(Bob) or (player) or whatever.

Could you help me to set up this little function? I bet it has something to do with Int and strings and breeding those (or rather trying to), but I just can point it out.

Thanks in advance!

HegemonKhan
this may help, while I'm trying to take a look at it:

http://docs.textadventures.co.uk/quest/ ... ction.html

I'll get back to you soon.

The Pixie
This:
msg (GetRandomInt(1,object.trait))

... is trying to find an attribute called "trait". Try this instead:
msg (GetRandomInt(1,GetInt(object, trait)))

HegemonKhan
got it, but not sure why it seems to only work this way:

http://docs.textadventures.co.uk/quest/ ... ibute.html

<function name="rollattribute" parameters="object, trait">
x = GetAttribute (object,trait)
msg (GetRandomInt(1,x))
</function>


------

Pixie beat me to it, we're doing the same thing... but I'm still not understanding why.. hmm...

josaaku
The Pixie wrote:This:
msg (GetRandomInt(1,object.trait))

... is trying to find an attribute called "trait". Try this instead:
msg (GetRandomInt(1,GetInt(object, trait)))


Works! I called it with rollattribute (player, "agility") and it works perfectly well, thanks a lot!

EDIT: The other solution works as well, HegemonKhan. This is good to know, now I have two ways to solve this, maybe one will work for this problem, maybe the other will work for that problem... it's always good to know all possibilities.

Thanks to both of you!

HegemonKhan
@Pixie or whoever else knowledgeable:

why does this not work (why is it not substituting in the value automatically?) :

object.trait

but this does work (forcibly getting the value):

GetInt (object,trait)

as I don't see the difference between them... ????

object.trait = GetInt (object, trait)

player.agility = 50

player.agility = 50 = GetInt (player, "agility")

.... hmmm......

Pixie wrote:is trying to find an attribute called "trait"


... hmmm .......

so, it's literally trying to do the Attribute: object.trait

but... why isn't 'trait' getting subtituted with 'agility'',whereas, I presume, that 'object' is successfully being substituted with 'player', right (or is 'object' also unable to be~get substituted over to 'player' as well?), I don't understand the reasoning~logic of how~why the substitution isn't happening in this case, when it seems like it should be... ???

--------

@josaaku:

my way and Pixie's are the same, I just split it into two steps, Pixie kept it in one step.

'GetAttribute' is a broad function that will work with any Attribute Type

'GetInt' is specificially for an Integer Attribute
'GetString' ....
'GetBoolean' ....
'GetDouble' .....
etc etc etc

The Pixie
The GetInt or GetAttribute functions expect an object and a string containing the name of the attribute. So GetInt(player, trait) will get the attribute that has the name stored in the variable trait. You could also do it with GetInt(player, "agility"), that will do the same thing (if trait = "agility").

"trait" is the name of a variable that contains the name of the attribute
"agility" is just the name of the attribute

On the other hand, player.agility will get the attribute called "agility".

The reason they do it differently is that Quest was written that way, and it was written that way to make it easy to use attributes (via player.agility) whilst still having the flexibility to do it either way (via GetInt(player, trait) or GetInt(player, "agility")).

HegemonKhan
ah, thank you Pixie, so it's just the underlying code wasn't built to apply the Parameter substitutes with~for~into the Attribute syntax: Object.Attribute. It isn't built to parse between a direct Object.Attribute and a Param_Sub_for_Object.Param_Sub_for_Attribute

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

Support

Forums