Spellcasting.

Hi,

I'm trying to create a spellcasting system, and it is not going well at all. I have found that the only way I can "cast" a spell, is if I had an attribute to an object called spell, and have it a Boolean as true for the attribute added. Then I create a verb cast for that object and get a prompt, and IF it is a specific object.attribute, then the spell gets cast. Or stated in another way:

cast spell ... get prompt and type in ... spell.healing ... if (expression) = spell.healing ... spell is then cast.

This gets cumbersome VERY quickly as:

  1. You need an attribute for every single spell in the game.
  2. You need an if statement for every single spell in the game.
  3. You cast the spell by typing into the prompt: spell.attribute, which would look weird to a user.

So, I'd prefer to use a command to perform spellcasting over using a verb on an object. The issue though is that, the command only allows for #object#, #text# or #exit#.

If I set it to "object", then I need to "be able to see it", and thus either on the ground or in your inventory, which will clutter up your inventory quickly or clutter up ground objects quickly. This also means that every spell needs to be a separate object.

If I set it to "text", then the word "healing" gets put into #text#, but then I can't use it. I've tried using text or #text# in a switch statement, with healing as a key, but this either spews an error or nothing happens. So, I'd prefer it if the user could use a command of "cast #text#", to perform spellcasting, but I don't know how to use the information stored in #text# to cause a spell to be cast.

How can I use #text#, once I put something into #text#?

Or is there an alternative way that could be suggested on how to do spellcasting? If I could have a dropdown menu, like Inventory on the interface, then that would be an ideal place to store spells, but I don't know how to add interface elements.


If you are using the desktop version, I suggest using a library. This has a tutorial that will take you through how to use it.

https://github.com/ThePix/quest/wiki/CombatLib

Second inventory pane for spells here:
https://github.com/ThePix/quest/wiki/Second-Inventory-Library


Pixie's Combat Library has his magic/spell library stuff inside of it (long ago it was a separate library/guide in the doc site).

this kind of stuff is really advanced to try to do on your own... so use Pixie's library.

the ingenious part of Pixie's magic/spell library is the use of Dictionary Attributes for the handling of: 'weakness (opposing elementals: x2 or x1.5 damage)', the same elementals: 'strength-resistance (x0.5 or x0.33 or x.67 damage)/absorption (heals instead of damages)/reflection (damage is done upon the caster, usually reduced damage, such as at x0.5, instead of the target)' , and non-same non-opposite elementals (normal damage: x1.0 and normal effect: upon target), as/of the types of spell effects/damages.

well, all of Pixie's spell/magic library is ingenious, in how he handles all the types of spells/magic... I still need to study this stuff more/better... but I was just amazed at the how Dictionaries can be used for handling the different types of spells effects/damages.

it took me a long time to understand this stuff, so if you're interested in it too, and want to understand it, I (or Pixie of course) can help you with it.


I tried adding a library with my previous project. It borked it, and had to start from scratch, so I'll pass on the library.

I also, already have my own system for equipping objects, doing attack systems, and have a specific style of gameplay in mind, that wouldn't work with most of the features of the CombatLib (I read through most of it to see what it has to offer, and my current solutions solve my own gameplay situation much more elegantly), and so, it looks like I'll have to figure out a different way to solve spellcasting.

Thanks for taking the time to reply, though. Appreciate it.


tell us your design and specific needs with spells/magic and we can help you with them.


some ideas below... I've not done any spell work yet... so not even close to the best designs, but hopefully it'll give you some ideas on how you can do some things.

Pixie can provide much better designs for you


you can use 'Object Types' and have the casting Script Attribute's name be the same for all spells, thus letting you cast any spell, for example:

<object name="fireball">
  <inherit name="spell_type" />
  <inherit name="fire_type" />
  <inherit name="damage_type" />
  <attr name="damage" type="int">50</attr>
</object>

<object name="healing">
  <inherit name="spell_type" />
  <inherit name="holy_type" />
  <inherit name="healing_type" />
  <attr name="damage" type="int">25</attr>
</object>

<type name="damage_type">
  <attr name="damage" type="int">0</attr>
</type>

<type name="healing_type">
  <attr name="damage" type="int">0</attr>
</type>

<type name="fire_type">
  <attr name="elemental_string_attribute" type="string">fire</attr>
</type>

<type name="holy_type">
  <attr name="elemental_string_attribute" type="string">holy</attr>
</type>

<type name="monster_type">
</type>

<type name="undead_type">
</type>

<type name="spell_type">
  <attr name="cast" type="script">
    if (DoesInherit (this, "spell_type") and DoesInherit (this, "damage_type") {
      foreach (object_variable, GetDirectChildren (player.parent)) {
        if (DoesInherit (object_variable, "monster_type")) {
          if (object_variable.elemental_string_attribute = this.elemental_string_attribute) {
            msg (object_variable.alias + " is immune to " + this.elemental_string_attribute + ", no damage done to it.")
          } else if (object_variable.elemental_string_attribute = StringDictionaryItem (game.opposing_elementals_stringdictionary_attribute, this.elemental_string_attribute) {
            object_variable.current_life_intger_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute * 2
            msg (object_variable.alias + " is weak to " + this.elemental_string_attribute + ", you do double damage to it")
          } else {
            object_variable.current_life_intger_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute
            msg ("You do normal damage to " + object_variable.alias)
          }
        } 
      }
    } else if (DoesInherit (this, "spell_type") and DoesInherit (this, "healing_type")) {
      ask ("Self (yes/true) or Enemies (no/false)?") {
        if (result) {
          player.current_life_integer_attribute = player.current_life_integer_attribute + this.damage_integer_attribute
          msg ("you heal yourself")
        } else {
          foreach (object_variable, GetDirectChildren (player.parent)) {
            if (DoesInherit (object_variable, "monster_type") and DoesInherit (this, "undead_type")) {
              object_variable.current_life_integer_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute * 3
              msg (this.alias + " does 3 times damage to the undead " + object_variable.alias)
            }
          }
        }
      }
    }
  </attr>
</type>

about using Commands:

there's a bit more code work involved with using #object#, so you can use the #text# instead and use the 'GetObject (text)' Function with it.... actually, it still has the problem with if you do't know the Object's name (only know its alias for example, as the object's name is hidden from the person playing the game)... see Pertex' fix at bottom. If I remember right, using #object# will handle this for you automatically (if it can't find an Object's name of the input, it'll see if it can find an Object's alias of the input), but using #object# has the problem of the if out of scope (which using #text# and GetObject(text) doesn't)... both #text# and #object# have their pros and cons, lol.

<command name="cast_command">
  <pattern>cast #text_parameter#</pattern>
  <script>
    object_variable = GetObject (text_parameter)
    if (DoesInherit (object_variable, "spell_type")) {
      do (object_variable, "cast")
    }
  </script>
</command>

Pertex also provided this for handling non-accessable-Objects-for-a-Command:

(from my combat code, when I was trying to learn combat coding for the first time, using Pertex' Combat library as a guiding structure for my combat code)

enemy_variable = GetObject (text)
if (enemy_variable = null) {
  foreach (object_variable, AllObjects ()) {
    if (object_variable.alias = text) {
      enemy_variable = object_variable
    }
  }
}
if (enemy_variable = null) {
  msg ("There is no " + text + " here.")
}

ask if you need help with anything or got any questions


I plan on having global commands for my spells/attack-types for my combat system. Not sure if this is more helpful or not.

I simply created a say [spell name]/cast [spell name] global command for my games. If the player has learned the spell, the spell will be cast on the monster in the room. If they have not learned that spell, it will result in an "error" message.

Much simpler than some alternatives. Just depends on your system, I guess.


My $.02...
lordpalandus is looking to make a club to hit the orc...
You guys are trying to give him a 25KT tac nuke...

You are providing too much help and are causing answer overload.
I have programmed in Basic for 35 or so years and about 30 days worth of OOP and Quest...
90% of your answers are over my head!!!
Break down your answer to a level a noob can understand.
You are trying to be being helpful, which is good, but break down your answers to what you needed when you were trying to learn this.
I can see where you are following OOP logic, making everything objects, and making functions to do anything providing you give the right parameters.
When I program, I don't focus on function and subroutines at first, until I start to repeat the same code more than 3 or 4 times, then I will recode to use a function to do the work. True, maybe a little extra work, but that is the best way to learn, by reworking and recoding a project. (not recommended when you are paid to program or you are making a game the size of War and Peace!) Hopefully, buy that time you can think in OOP and 4 to 5 functions ahead.

In time, I'm sure everyone can get to your levels on knowledge, but until then, simplify your answers... please!!!
Rant: yes...
Flame: No!!! Defiantly not!
Just a plea to answer with simpler answers...


from my reading, it doesn't sound like he/she is asking for a club, as that is what he/she was doing, and it's too cumbersome... he/she wants a more global/OOP/OOD design, so he/she isn't doing so much manual work for every Object/spell/effect/etc individually himself/herself:

"
(from Lord Palandus' OP)

I'm trying to create a spellcasting system, and it is not going well at all. I have found that the only way I can "cast" a spell, is if I had an attribute to an object called spell, and have it a Boolean as true for the attribute added. Then I create a verb cast for that object and get a prompt, and IF it is a specific object.attribute, then the spell gets cast. Or stated in another way:

cast spell ... get prompt and type in ... spell.healing ... if (expression) = spell.healing ... spell is then cast.

This gets cumbersome VERY quickly as:

You need an attribute for every single spell in the game.
You need an if statement for every single spell in the game.
You cast the spell by typing into the prompt: spell.attribute, which would look weird to a user.
So, I'd prefer to use a command to perform spellcasting over using a verb on an object. The issue though is that, the command only allows for #object#, #text# or #exit#.
"


here Lord Palandus is asking about how to work with Commands:

"
So, I'd prefer to use a command to perform spellcasting over using a verb on an object. The issue though is that, the command only allows for #object#, #text# or #exit#.
"

which I try help with this (from my previous post):

"
about using Commands:

there's a bit more code work involved with using #object#, so you can use the #text# instead and use the 'GetObject (text)' Function with it.... actually, it still has the problem with if you do't know the Object's name (only know its alias for example, as the object's name is hidden from the person playing the game)... see Pertex' fix at bottom. If I remember right, using #object# will handle this for you automatically (if it can't find an Object's name of the input, it'll see if it can find an Object's alias of the input), but using #object# has the problem of the if out of scope (which using #text# and GetObject(text) doesn't)... both #text# and #object# have their pros and cons, lol.

<command name="cast_command">
  <pattern>cast #text_parameter#</pattern>
  <script>
    object_variable = GetObject (text_parameter)
    if (DoesInherit (object_variable, "spell_type")) {
      do (object_variable, "cast")
    }
  </script>
</command>

Pertex also provided this for handling non-accessable-Objects-for-a-Command:

(from my combat code, when I was trying to learn combat coding for the first time, using Pertex' Combat library as a guiding structure for my combat code)

enemy_variable = GetObject (text)
if (enemy_variable = null) {
  foreach (object_variable, AllObjects ()) {
    if (object_variable.alias = text) {
      enemy_variable = object_variable
    }
  }
}
if (enemy_variable = null) {
  msg ("There is no " + text + " here.")
}

"


and he's/she's (Lord Palandus is) asking for a way to not do so much manual work on every individual thing here:

"
I'm trying to create a spellcasting system, and it is not going well at all. I have found that the only way I can "cast" a spell, is if I had an attribute to an object called spell, and have it a Boolean as true for the attribute added. Then I create a verb cast for that object and get a prompt, and IF it is a specific object.attribute, then the spell gets cast. Or stated in another way:

cast spell ... get prompt and type in ... spell.healing ... if (expression) = spell.healing ... spell is then cast.

This gets cumbersome VERY quickly as:

You need an attribute for every single spell in the game.
You need an if statement for every single spell in the game.
You cast the spell by typing into the prompt: spell.attribute, which would look weird to a user.
"

which I try to help with giving one method of reducing the manual work of a spell system:

(from my previous post)

(this is very poor code, Pixie and his library is much better, but this gives some idea/look into this stuff, which Pixie does much better with in his code/library)

"
you can use 'Object Types' and have the casting Script Attribute's name be the same for all spells, thus letting you cast any spell, for example:

<object name="fireball">
  <inherit name="spell_type" />
  <inherit name="fire_type" />
  <inherit name="damage_type" />
  <attr name="damage" type="int">50</attr>
</object>

<object name="healing">
  <inherit name="spell_type" />
  <inherit name="holy_type" />
  <inherit name="healing_type" />
  <attr name="damage" type="int">25</attr>
</object>

<type name="damage_type">
  <attr name="damage" type="int">0</attr>
</type>

<type name="healing_type">
  <attr name="damage" type="int">0</attr>
</type>

<type name="fire_type">
  <attr name="elemental_string_attribute" type="string">fire</attr>
</type>

<type name="holy_type">
  <attr name="elemental_string_attribute" type="string">holy</attr>
</type>

<type name="monster_type">
</type>

<type name="undead_type">
</type>

<type name="spell_type">
  <attr name="cast" type="script">
    if (DoesInherit (this, "spell_type") and DoesInherit (this, "damage_type") {
      foreach (object_variable, GetDirectChildren (player.parent)) {
        if (DoesInherit (object_variable, "monster_type")) {
          if (object_variable.elemental_string_attribute = this.elemental_string_attribute) {
            msg (object_variable.alias + " is immune to " + this.elemental_string_attribute + ", no damage done to it.")
          } else if (object_variable.elemental_string_attribute = StringDictionaryItem (game.opposing_elementals_stringdictionary_attribute, this.elemental_string_attribute) {
            object_variable.current_life_intger_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute * 2
            msg (object_variable.alias + " is weak to " + this.elemental_string_attribute + ", you do double damage to it")
          } else {
            object_variable.current_life_intger_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute
            msg ("You do normal damage to " + object_variable.alias)
          }
        } 
      }
    } else if (DoesInherit (this, "spell_type") and DoesInherit (this, "healing_type")) {
      ask ("Self (yes/true) or Enemies (no/false)?") {
        if (result) {
          player.current_life_integer_attribute = player.current_life_integer_attribute + this.damage_integer_attribute
          msg ("you heal yourself")
        } else {
          foreach (object_variable, GetDirectChildren (player.parent)) {
            if (DoesInherit (object_variable, "monster_type") and DoesInherit (this, "undead_type")) {
              object_variable.current_life_integer_attribute = object_variable.current_life_integer_attribute - this.damage_integer_attribute * 3
              msg (this.alias + " does 3 times damage to the undead " + object_variable.alias)
            }
          }
        }
      }
    }
  </attr>
</type>

"


but I tend to over-think stuff, so maybe he/she didn't want this stuff, but I've shown why I understood the reading of his/her post to be asking of this stuff, but I could be totally wrong about what he/she was asking for too, sighs.


using OOP/OOD stuff like Commands, Functions, Object Types, scripting (having quest generate stuff for you: when the game play begins: via having it in the 'start' Script of the 'game' Game Settings Object or for Game Book on your first page, instead of you coding in everything individuallly yourself in the GUI/Editor or in-code), and Lists/Dictionaries/iteration/recursion/looping/etc, is very advanced and not easy stuff, far more advanced then what the basic GUI/Editor functionality you learn through the tutorial.

not easy for someone just starting out with quest and especially for someone new to coding/programming. This is really a lot of advanced stuff and requires a ton of logic and organizational-foresight to have everything working correctly together for OOD/OOP (which I highly struggle at myself - I failed the Data Structures / OOP / OOD programming class: abstract chained links, dictionaries, maps, etc etc etc. my brain just wasn't able to jump from proceedural stuff into this OOP level of design and synchronization of everything together: abstract encapsulation, sighs)


if we could see Lord Palandus' code, we can help him/her more specifically/simplistically/targetted/concisely, but right now, we just got a vague idea from his/her post's content/description, so our responses/posts are also quite thus generalized and not specific/simplistic/targeted/concise for what he/she wants and/or how to help him/her with learning whatever the new stuff is that he/she needs for what he/she wants to do, to improve his/her coding design.


it's interesting how younger people are introduced to the new high level languages, and struggle with learning the earlier high level languages and/or low-level languages, and how older people were introduced to the earlier high level languages and/or low-level languages, but struggle with learning the new high level languages. It's like younger people struggle in learning what old people know, and old people struggle in learning what new people know. I'm not exactly too young myself... I'm jsut now trying to learn computers, and am trying to learn programming... but I am a complete dinosaur with these mobile devices and their apps... I just have a cell phone for emergences, but I otherwise never use it, and I definately don't have nor use any of these mobile devices: ipods, ipads, tablets, etc etc etc... At some point, I need to learn mobile devices, but right now, I'm just trying to learn the computer itself, programming, networking, IT / OS / computer system, security, and etc... sighs. Unfortunately, I never really knew much about computers when I was younger, never tried to learn them, only wrote school papers on them and played games and only used internet casually, sighs... lots of catching up to do... sighs.


anyways, back on subject...

we'd be happy to explain and help with understanding and work with you in using these things if you don't know how to use them:

Object Types (quest's user-level groups/classes/'templates --- not to be confused with quest's Template Element'), Commands (pattern:Arguments/Parameters and etc), Functions (Arguments/Parameters and/or directly returned value outputs) / Delegates (Script Attributes with having the same Arguments/Parameters and/or return value outputs as Functions), List/Dictionary Attributes and their usage of iteration(foreach/for/while)/recursion/looping/etc, and etc advanced concepts/features of quest.


we need to take one thing at a time, of course, but we can go into the specifics on all of these things, teaching you how to use them.


Here is what I think the OP wants...
The troll hits you for 12 points, you have 5 HP remaining.
/> cast heal
You heal for 8 points. you are now at 13 HP.
The troll swings, but misses.
/> cast fireball
You fry the troll for 22 points.
The troll fall over into a burning pile.
You get 53 XP from the battle.

OK, Question...
How does Quest read the command bar?
When I type in "cast heal", what/ where is that processed?
Could a "switch" be used to read the command bar to determine what was typed?
I know Quest handles most of the parsing itself, (I bet this would be a command)


This may be the answer...
http://docs.textadventures.co.uk/quest/commands_with_unusual.html
or this
http://docs.textadventures.co.uk/quest/using_verbs.html
(But I am at a loss with them!!! :( )


there's two ways to get typed-in input:

  1. the 'get input' Script/Function: http://docs.textadventures.co.uk/quest/scripts/get_input.html
  2. the 'Command' Element: http://docs.textadventures.co.uk/quest/elements/command.html

the 'Command' element:

<command name="heal_command">

  <pattern>heal #object_parameter_1#</pattern> // this is what you type in (into the command/text box during game play), to activate this command, the first word(s) acts as like the 'activator' determining which Command is to be used/activated, so make sure its clearly unique so you don't get into parser issues... and the #object/objectXXX/text/textXXX# are Parameters that store your typed-in input (used as Arguments), to be used in the Command's scripting, just like a Function's Parameter uses Arguments/inputs in the Function's 'call (usage)', using them in the Function's scripting. The parser requires that your '#XXX#' starts with 'object' or 'text', so you can use: #object# or #text# or #object_parameter_1# or #object1# or #text_parameter_1# or #text1# (I like being descriptive, so I'd personally use this name for it: #text_parameter_1#, #text_parameter_2#, #object_parameter_1#, #object_parameter_2#. You can have as many Parameters as you want, using whatever patterns you want: mix #object1# and #object2# and #object3#, or: mix #object1#, #object2#, and #object3#, etc etc etc. You can use #object# and #text# together too, they don't all have to be #object# or #text#. Finally, when you use the Parameter in the Command's scripting, you remove the # symbols from it: as a Parameter in the pattern: #text#, but as scripting: msg (text). The # symbols are used by the pattern's parsing to tell it that these typed-in inputs are to be used as (stored into the) Parameters.

  <script>
    object_parameter_1.current_life_integer_attribute = object_parameter_1.current_life_integer_attribute + 100
    msg ("You healed " + object_parameter_1.name + " for +100 life")
  </script>

</command>

I used simplistic scripting for the Command above, but everything you can do in normal scripting (Verbs/Functions), you can do with a Comamnd's scripting, so you can certainly use the 'switch' block, for example (a bit more complex scripting Command):

<command name="cast_command">
  <pattern> cast #object_parameter_1# on #object_parameter_2#</pattern>
  <script>
    if (DoesInherit (object_parameter_1, "damage_spell_type") and object_parameter_1.parent = player and object_parameter_2.parent = player.parent and DoesInherit (object_parameter_2, "monster_type") and not object_parameter_2.condition_string_attribute = "dead") {
      switch (object_parameter_1.name) {
        case ("fireball") {
          object_parameter_2.current_life_integer_attribute = object_parameter_2.current_life_integer_attribute - 50
        }
        case ("armaggeddon") {
          object_parameter_2.current_life_integer_attribute = object_parameter_2.current_life_integer_attribute - 999
        }
      }
    }
  </script>
</command>

<object name="room">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
</object>

<object name="fireball">
  <inherit name="damage_spell_type" />
  <attr name="parent" type="object">player</attr>
</object>

<object name="armaggeddon">
  <inherit name="damage_spell_type" />
  <attr name="parent" type="object">player</attr>
</object>

<object name="orc">
  <inherit name="monster_type" />
  <attr name="parent" type="object">room</attr>
  <attr name="condition_string_attribute" type="string">normal</attr>
</object>

<type name="damage_spell_type">
</type>

<type name="monster_type">
</type>

ask if you need any questions... how the Parameters work is quite confusing... and I probably didn't make it any clearer trying to explain it, lol. So feel free to ask about anything... and I'll try to do a better job this next time around, lol.


Commands as direct children of the 'asl' tag block (aka they're NOT inside of a Room Object) are global, you can activate them anywhere in your game.

Commands that are inside of a Room Object, can only be activated when you're in that Room Object: they're local to that Room Object.


Verbs are actually Commands, but further specified/limited/specialized in scope to just be local to the Object you add/attach them into/to. Verbs work as they do, as they're also just Script Attributes (have Script Attribute properties) with extra coding for giving them their Verb functionality (being able to see them as buttons/hyperlinks via adding them to the 'displayverbs' and/or 'inventoryverbs' Stringlist Attributes) as opposed to just normal Script Attributes, and as stated, they're also just specialized Commands, so they're also connected to Commands, though I'm not quite sure on how to get some action to work as both a Verb and as a Command, but it can be done. I'm still confused by it myself.


here's some links on Commands:

http://docs.textadventures.co.uk/quest/tutorial/custom_commands.html

http://docs.textadventures.co.uk/quest/tutorial/custom_commands.html
http://docs.textadventures.co.uk/quest///commands_with_unusual.html
http://docs.textadventures.co.uk/quest/complex_commands.html
http://docs.textadventures.co.uk/quest/elements/command.html
http://textadventures.co.uk/forum/quest/topic/ij9pztcxquaeiozydrxi_a/allow-a-command-to-require-object1-for-an-action-on-object2
http://docs.textadventures.co.uk/quest/tutorial/anatomy_of_a_quest_game.html (tiny part on Commands: see 'Verbs and Commands' small section)
http://textadventures.co.uk/forum/quest/topic/yplgutcqlk_vdtn3tc4ksg/command-patterns
http://textadventures.co.uk/forum/quest/topic/yfg1yancq0meniur8hqoba/adding-other-verbs-to-default-commands
http://textadventures.co.uk/forum/quest/topic/2669/verb-vs-command (see Alex' post, he explains Commands well)
http://textadventures.co.uk/forum/quest/topic/1570/what-is-the-difference-between-verbs-and-commands (another of Alex' posts on Commands)


There are (at least) three ways to approach this for the command pattern:

cast healing

cast #object#

cast #text#

The first is the simplest, but you will need to do one command for each spell in the game (which may not be a big deal). The problem with the with the second is the spells need to be objects in the player inventory, so will add to the inventory list (and verbs are a shortcut to this, so this applies to them too). The problem with the third is you then have to match the text to spells yourself (which the "Commands with Unusual Scope" page DarkLizerd linked to takes you through). I personally would (and did) do the last.


Well, again thanks for all the replies, but all of your responses, again, require me to do coding in JavaScript, which I do not understand. I barely understand C++; I can read it, but I can't code it. All of the links, requires one to do coding. None of the links explains how to do these things, IN ENGINE GUI EDITOR, over doing it manually with code.

I've decided on an inelegant, but workable solution with what I can do with the in engine GUI editor. Any self-cast spells, cast on the player only, will be made as "verbs" for the player object; ie "cast healing on player". All combative spells will be done in the form of commands, such as cast firebolt at #object#. A very cumbersome, an inelegant method, but it works, as I've tested it. Will involve a lot of work on my end, but it works, and I can do it in the GUI editor WITHOUT having to resort to doing JavaScript coding.

If someone can offer me a solution that can be done exclusively in the in engine GUI editor and doesn't require coding in JavaScript, and only using existing functions or variables in engine, then I'd be happy to hear it and look at changing my system around. But, as most of the more advanced stuff for Quest requires doing things in JavaScript, I doubt very much that you guys will be able to find anything. So... yah, inelegant, cumbersome system for spellcasting it is!

EDIT:

On the other hand, the way I intended to use spellcasting in my game, it might be best if I did anyway create a separate command for each spell. So, even if I did have the option to do it some other way, this might be the best possible solution anyway.

What I mean is that in my game, there is three different playstyles, combat/stealth/magic, and each gives specific loot depending on how the target foe is bypassed; combat kills the target, stealth pickpockets them and leaves the room, and magic damages the target and then casts a spell that disables them (ie paralysis, sleep, polymorph, etc) instead of outright killing them. And as each disabling spell has different conditional effects that require to be satisfied in order to occur, its probably for the best that each spell is a separate command.


I would just treat the spell as a regular attack function.

The only way I know to do it is to use separate commands and functions. (Or just one really big function, I guess.)

I took a look at The Pixie's spell library. Most of it is just text and attributes.

For instance, here is a "small" sampling of that Zombie code (small compared to the rest that is). I deleted the turn script, (turned it into a function) but you can still find Pixie's original "game code" which does have a turn script.
Link to the game (mine): http://textadventures.co.uk/games/view/kmwqh7zyrkcrseuqrzuigg/zombie-2
(I use the web version)

attack command
attack #object#
if (not HasBoolean(object, "dead")) {
msg ("That's not something you can attack.")
}
else if (object.dead) {
msg ("That one is already dead.")
}
else {
if (player.equipped = null) {
DoAttack (player, player, object)
attackturnscript
}
else {
DoAttack (player, player.equipped, object, false)
attackturnscript
}
}
DoAttack
(parameters: attacker; weapon; target; firearm)
if (firearm) {
damageatt = "firearmdamage"
attackatt = "firearmattack"
weapon.ammo = weapon.ammo - 1
}
else {
damageatt = "damage"
attackatt = "attack"
}
roll = GetRandomInt(1, 20) + GetInt(weapon, attackatt) - target.defence
if (HasInt(weapon, damageatt)) {
damage = GetInt(weapon, damageatt)
}
else {
damage = DiceRoll(GetString(weapon, damageatt))
}
damage = damage * (100 - target.armour) / 100
if (damage < 1) {
damage = 1
}
if (roll > 15) {
damage = damage * 3
msg (CapFirst(attacker.alias) + " attack " + target.alias + " and get a critical (" + damage + " hits)!")
target.hitpoints = target.hitpoints - damage
}
else if (roll > 4) {
msg (CapFirst(attacker.alias) + " attack " + target.alias + " and hit (" + damage + " hits).")
target.hitpoints = target.hitpoints - damage
}
else {
msg (CapFirst(attacker.alias) + " attack " + target.alias + " and miss...")
}
attackturnscript (I turned it into a function)
if (not game.notarealturn) {
list = NewObjectList()
foreach (obj, GetDirectChildren(player.parent)) {
if (HasBoolean(obj, "dead")) {
if (not obj.dead) {
DoAttack (obj, obj, player, false)
list add (list, obj)
}
}
}
foreach (obj, ListExclude(player.attackers, list)) {
if (not obj.dead and RandomChance(80)) {
obj.parent = player.parent
msg (CapFirst(obj.alias) + " shambles into the area.")
list add (list, obj)
}
}
player.attackers = list
}
game.notarealturn = false


Log in to post a reply.

Support

Forums