Attack spells; casting a spell on an object
AvecPardon
15 Apr 2012, 04:54Another of those things that I've been trying to figure out on my own, but can't quite grasp. (I'm a writer, not a coder.
)
So I managed to get healing spells to work fine in my game, but now I'm trying to integrate attack spells. I only have one to test with, and everything I've done to try to get it to work has pretty much failed. I've tried setting up the custom command to include 'cast #text# on #object#' and it just brings up a list of everything in the room, which I don't want. If I remove the 'on #object#' part, it just errors. I've tried switch commands embedded in it, changing the names of the target objects, creating attributes for the spell to target, and other things too numerous to remember. Nothing's worked.
I just want to be able to cast the spell 'Luna Flare' on an enemy object, recognize there IS an enemy object to be targeted, and carry out the effects intended. Here's a screenshot of what I've got of it so far, as well as the game file and accompanying library. Can anyone explain where I've gone wrong this time, please? Thanks much.

The attempted embedded switch scripting to target specific objects.

The custom command itself.

So I managed to get healing spells to work fine in my game, but now I'm trying to integrate attack spells. I only have one to test with, and everything I've done to try to get it to work has pretty much failed. I've tried setting up the custom command to include 'cast #text# on #object#' and it just brings up a list of everything in the room, which I don't want. If I remove the 'on #object#' part, it just errors. I've tried switch commands embedded in it, changing the names of the target objects, creating attributes for the spell to target, and other things too numerous to remember. Nothing's worked.
I just want to be able to cast the spell 'Luna Flare' on an enemy object, recognize there IS an enemy object to be targeted, and carry out the effects intended. Here's a screenshot of what I've got of it so far, as well as the game file and accompanying library. Can anyone explain where I've gone wrong this time, please? Thanks much.

The attempted embedded switch scripting to target specific objects.

The custom command itself.

Pertex
15 Apr 2012, 08:25Sorry, Beta2 is released and I am so excited testing it that I have not much time to look at other things now
But try to change the order of the command pattern, use 'cast #text# on #object2#;cast #text#'

But try to change the order of the command pattern, use 'cast #text# on #object2#;cast #text#'
AvecPardon
17 Apr 2012, 16:54Hmm, I tried switching the command text around, but that still gives me the error that it can't find the objects I want targeted. Anyone else want to give it a try and see where I messed up?
I wonder if I can get a bit more leeway if I rewrite the game using Quest 5.2?
I wonder if I can get a bit more leeway if I rewrite the game using Quest 5.2?
sgreig
17 Apr 2012, 17:25If you could re-post the aslx file I can take a look at it. I haven't done any testing on this mind you, but I'm wondering if part of the issue is that your spells are two words? I think (I may be wrong) that using the command pattern "cast #text# on #object#", if you typed in "cast luna flare on troll", Quest would put luna into the variable text, but it wouldn't know what to do with flare.
This is just conjecture however. But maybe as an experiment try changing luna flare to lunaflare and see if that makes a difference?
This is just conjecture however. But maybe as an experiment try changing luna flare to lunaflare and see if that makes a difference?
AvecPardon
17 Apr 2012, 17:41All right, I'll give that a try, and I reposted the aslx after making a few more adjustments in spelling.
Edit: Okay so I gave that a try by adding in a hyphen. I tested the spell out on both an inanimate object (a table) and an enemy object (a security guard).
Using it on the table gets me the following: Error running script: Object reference not set to an instance of an object. I'm guessing that means it errors because it's not one of the intended target objects.
Using it on the guard just has the script I set up for no target available run, as if it didn't even register that a target object was there. Hmm, tricky.
But at least it recognizes I used a spell, that's a step in the right direction!
Edit: Okay so I gave that a try by adding in a hyphen. I tested the spell out on both an inanimate object (a table) and an enemy object (a security guard).
Using it on the table gets me the following: Error running script: Object reference not set to an instance of an object. I'm guessing that means it errors because it's not one of the intended target objects.
Using it on the guard just has the script I set up for no target available run, as if it didn't even register that a target object was there. Hmm, tricky.
But at least it recognizes I used a spell, that's a step in the right direction!

Pertex
17 Apr 2012, 20:04I think one problem is the command pattern. All parts of the pattern should have the same variables (#text# and #object#)
"Using it on the table gets me the following: Error running script: Object reference not set to an instance of an object."
You are right. You should add <enemy/> to a type (perhaps to mob?) and check it in the castcommand with
So if the object does not inherit this type nothing happens.
Then I just notice, that your switch is a bit buggy. You are testing object.enemy which is only a flag with values true or false. So you cant use secguard as a key in the case. You should use enemy.name in the switchargument.
And where is the object sec_guard2 in your game? You use it as a key (and another time with a moveobject command) but I cant find the object.
"Using it on the table gets me the following: Error running script: Object reference not set to an instance of an object."
You are right. You should add <enemy/> to a type (perhaps to mob?) and check it in the castcommand with
If (not DoesInherit ( object , "mob" ) ) {
msg("nothing happens")
} else {
...
So if the object does not inherit this type nothing happens.
Then I just notice, that your switch is a bit buggy. You are testing object.enemy which is only a flag with values true or false. So you cant use secguard as a key in the case. You should use enemy.name in the switchargument.
And where is the object sec_guard2 in your game? You use it as a key (and another time with a moveobject command) but I cant find the object.
AvecPardon
17 Apr 2012, 22:42Hmm, quite a number of things to check for, but I'll give it my best. I've managed to get it to recognize the first key by changing it to secguard.enemy, but I'll see if this way you're pointing out may be easier.
Secguard_2 is a summonable enemy found on the second floor of the game, and he's called by going into the bathroom and using either of the two palm scanners found there.
I'm going to try working with the inherit types suggestion, see how far I can get with that. Thanks for for the help, I'll post again with the results later on!
Secguard_2 is a summonable enemy found on the second floor of the game, and he's called by going into the bathroom and using either of the two palm scanners found there.
I'm going to try working with the inherit types suggestion, see how far I can get with that. Thanks for for the help, I'll post again with the results later on!

AvecPardon
18 Apr 2012, 02:06All right, I went through and applied the inherit types to the two key objects and it worked beautifully! Thanks so much!
My last hang-up is what to do if someone tries to just type in 'cast Luna-Flare' and doesn't specify an object. I did that for a test and got 'Error running script: Error compiling expression 'not DoesInherit (object, "mob")': Unknown object or variable 'object''. I've been poking at the scripting, trying to work in how to print a little message in response to that, since not specifying an object variable is generally treated as using the player as the target.
My last hang-up is what to do if someone tries to just type in 'cast Luna-Flare' and doesn't specify an object. I did that for a test and got 'Error running script: Error compiling expression 'not DoesInherit (object, "mob")': Unknown object or variable 'object''. I've been poking at the scripting, trying to work in how to print a little message in response to that, since not specifying an object variable is generally treated as using the player as the target.
sgreig
18 Apr 2012, 05:38One way to deal with this would be to use some string functions to check to make sure the player typed in a target and if not, deliver an error message. If you want to get really fancy you could have the game prompt them to enter the target if they forgot to enter one. The trick is figuring out how you want to determine it. It might be possible to do with regular expression if you're familiar with it, but I'm not sure how you would implement that. Another way would be to use string functions to check that the player typed an object, but again I'm not sure of the best way to test that.
As an example, in my game I have an option where the player can name the characters in the game, and I needed the player to enter both a first and last name in the format "firstname lastname", so I used an Instr function to check the input for a space, and if there was no space found, it prints a message to the player telling them there's a mistake and prompts them to enter it again.
I realize I probably haven't been very helpful, but maybe this will get you thinking along the right lines? I'm sure someone like Pertex or Alex could swoop in here and just tell you how to fix it, but this is a little out of my depth at the moment.
As an example, in my game I have an option where the player can name the characters in the game, and I needed the player to enter both a first and last name in the format "firstname lastname", so I used an Instr function to check the input for a space, and if there was no space found, it prints a message to the player telling them there's a mistake and prompts them to enter it again.
I realize I probably haven't been very helpful, but maybe this will get you thinking along the right lines? I'm sure someone like Pertex or Alex could swoop in here and just tell you how to fix it, but this is a little out of my depth at the moment.


Pertex
18 Apr 2012, 06:51I would suggest to replace your cast command. Try to use 2 commands with different pattern like this:
<command name="cast1">
<pattern>cast #text# on #object#</pattern>
<script>
// here you can add code for all spells with a target
</script>
</command>
<command name="cast2">
<pattern>cast #text#</pattern>
<script>
// here you can add code for all spells without a target
</script>
</command>
AvecPardon
18 Apr 2012, 15:26I hadn't thought you could make two commands that do about the same thing. Always figured it would cause a scripting conflict or something to that effect. I'll give this a shot. Thanks so much, everyone! Hope to have the results of this attempt soon. 

AvecPardon
01 May 2012, 02:51Tried splitting it into two commands and it worked wonderfully! Now I have the proper spells for offense and healing separated out with messages to alert the player when he's misusing one for the other. Thank you so much for the help!