Losign sight of the #object#

Espera
I thought I'd gotten commands down, but when it came to the most complex and most important command of my game, I can't seem to get it to work. When it comes time to do the calculations, the game tells me it doesn't know what object I'm referring to anymore. Here is the code for the script:

if (HasAttribute(object, "enemy")) {
SetObjectFlagOn (object, "incombat")
ShowMenu ("What will you do? ", player.movelist, false) {
switch (result) {
case ("kick") {
player.damage = player.Fight - object.fightres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You kick "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
case ("Magic Bolt") {
player.damage = player.Magic - object.magicres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You focus your magic at your horn and fire a Magic Bolt at "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
}
}
}


What am I doing wrong?

HegemonKhan
.

we really need to see your entire game code, to identify the problem, as we can't find the problem from just this code you provided.

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

I presume that this is scripting for a Command:

<command name="blah">
<pattern>blah #object#</pattern>
<script>
// blah_function or direct scripting here
</script>
</command>


in other words, in your scripting, your 'object' is connected to your command's pattern: blah #object#

also your command and~or function parameters need to be right too.

----

one possible problem with this method is that, if you gave your objects ALIASES, than you'll need to code for this, as quest searches for the objects' NAME when you type in 'blah object' during game play, so if you type in the object's alias, it can't get the object, as it is looking for an object with the NAME of what you typed in (its ALIAS). you'll need code to address this, if this is the issue.

-----

just a small (unrelated to your post's problem) mistake I noticed as well:

if (GetInt(player, "damage") = 0) {
player.damage = 0
}

you probably wanted it to be this:

if (GetInt(player, "damage") < 0) {
player.damage = 0

Espera
That is the command that isn't working. The rest of my game is working fine. What more do you need to know? It could very well be an issue with aliases, but if it is, what would I need to do in order to fix it?

Espera
To clarify, it is a command with the command pattern 'fight #object#'. The code I posted is for the script that command runs.

HegemonKhan
the reason that we need to see full game codes, is that individual parts of code are connected to other parts of code, so while the individual part of code that you post, might not have any error, the other segment(s) of code that use or are used by your posted part of code, can have the error, so that's why we often can't identify the problem, as the small part of code you post, doesn't have any error in it, but some other part of your game code, does. We need to make sure EVERYTHING matches up as it should, because your entire game code is one giant dependant interconnected web, and it ALL must be correct for it to work.

---------

see if this can help you, possibly see what the issue might be:

(using #object# for this, to make it clearer)

<command name="fight_command">
<pattern>fight #object#</pattern>
<script>
battle_system (game.pov,object)
</script>
</command>

<function name="battle_system" parameters="game.pov,object">
enemy = object
if (enemy = null) {
foreach (object_x,AllObjects()) {
if (object_x.alias=object) {
enemy = object_x
}
}
}
if (enemy = null) {
// scripts
} else {
// scripts
}


here's where you'd put this into your code (just a pseudo example):

<command name="fight_command">
<pattern>fight #object#</pattern>
<script>
battle_system (game.pov,object)
</script>
</command>

<function name="battle_system" parameters="game.pov,object">
enemy = object
if (enemy = null) {
foreach (object_x,AllObjects()) {
if (object_x.alias=object) {
enemy = object_x
}
}
}
if (enemy = null) {
// scripts
} else {
if (HasAttribute(object, "enemy")) {
SetObjectFlagOn (object, "incombat")
ShowMenu ("What will you do? ", player.movelist, false) {
switch (result) {
case ("kick") {
player.damage = player.Fight - object.fightres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You kick "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
case ("Magic Bolt") {
player.damage = player.Magic - object.magicres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You focus your magic at your horn and fire a Magic Bolt at "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
}
}
}


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

(I use #text# for this, however)

<asl version="530">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d83ba5bb-2e3c-4f31-80c9-3e88a2dc082c</gameid>
<version>1.0</version>
<pov type="object">player</pov>
<start type="script">
cc
</start>
<turns type="int">0</turns>
<statusattributes type="stringdictionary">turns = </statusattributes>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="defaultplayer" />
<inherit name="pc" />
<cur_hp type="int">999</cur_hp>
<max_hp type="int">999</max_hp>
<str type="int">100</str>
<end type="int">100</end>
<dex type="int">100</dex>
<agi type="int">100</agi>
<spd type="int">100</spd>
<hc type="int">100</hc>
<pd type="int">100</pd>
<pr type="int">100</pr>
</object>
<object name="orc1">
<inherit name="editor_object" />
<inherit name="npc" />
<hostile type="boolean">true</hostile>
<dead type="boolean">false</dead>
<alias>orc</alias>
<cur_hp type="int">999</cur_hp>
<max_hp type="int">999</max_hp>
<str type="int">25</str>
<end type="int">25</end>
<dex type="int">25</dex>
<agi type="int">25</agi>
<spd type="int">25</spd>
<hc type="int">25</hc>
<pd type="int">25</pd>
<pr type="int">25</pr>
</object>
</object>
<turnscript name="game_turns">
<enabled />
<script>
sa
game.turns = game.turns + 1
</script>
</turnscript>
<command name="fight">
<pattern>fight #text#</pattern>
<script>
battle_system (game.pov,text)
</script>
</command>
<type name="char">
<cur_hp type="int">0</cur_hp>
<drop type="boolean">false</drop>
<defending type="boolean">false</defending>
<max_hp type="int">0</max_hp>
<str type="int">0</str>
<end type="int">0</end>
<dex type="int">0</dex>
<agi type="int">0</agi>
<spd type="int">0</spd>
<hp type="int">0</hp>
<hc type="int">0</hc>
<pd type="int">0</pd>
<pr type="int">0</pr>
</type>
<type name="pc">
<inherit name="char" />
<statusattributes type="stringdictionary">hp = ;str = ;end = ;dex = ;agi = ;spd = ;hc = ;pd = ;pr = </statusattributes>
</type>
<type name="npc">
<inherit name="char" />
<dead type="boolean">false</dead>
<hostile type="boolean">false</hostile>
<displayverbs type="list">Look at; Talk; Fight</displayverbs>
</type>
<function name="cc">
msg ("What is your name?")
get input {
game.pov.alias = result
msg (" - " + game.pov.alias)
show menu ("What is your gender?", split ("male;female" , ";"), false) {
game.pov.gender = result
show menu ("What is your race?", split ("human;dwarf;elf" , ";"), false) {
game.pov.race = result
show menu ("What is your class?", split ("warrior;cleric;mage;thief" , ";"), false) {
game.pov.class = result
msg (game.pov.alias + " is a " + game.pov.gender + " " + game.pov.race + " " + game.pov.class + ".")
wait {
ClearScreen
}
}
}
}
}
</function>
<function name="sa">
game.pov.hp = game.pov.cur_hp + " / " + game.pov.max_hp
</function>
<function name="battle_system" parameters="self,text" type="boolean">
first_value = false
enemy = GetObject (text)
if (enemy = null) {
foreach (obj,AllObjects()) {
if (obj.alias=text) {
enemy = obj
}
}
}
if (enemy = null) {
msg ("There is no " + text + " here.")
first_value = false
}
else if (not Doesinherit (enemy,"npc")) {
msg ("You can not battle that!")
first_value = false
}
else if (not npc_reachable (enemy)) {
msg ("There is no " + enemy.alias + " in your vicinity.")
first_value = false
}
else if (GetBoolean (enemy,"dead") = true) {
msg (enemy.alias + " is already dead.")
first_value = false
}
else if (GetBoolean (enemy,"hostile") = false) {
msg (enemy.alias + " is not hostile.")
first_value = false
}
else if (battle_sequence (self,enemy) = true) {
msg ("The battle is over.")
first_value = true
}
return (first_value)
</function>
<function name="battle_sequence" parameters="self,enemy" type="boolean"><![CDATA[
second_value = false
if (enemy.dead = false) {
if (GetInt (self,"spd") > GetInt (enemy,"spd")) {
on ready {
msg ("You get to go first for this round")
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
}
on ready {
if (enemy.dead = false) {
if (enemy_battle_turn (self,enemy) = true) {
msg ("The round has ended.")
}
}
}
on ready {
battle_sequence (self,enemy)
}
}
else if (GetInt (self,"spd") < GetInt (enemy,"spd")) {
on ready {
msg (enemy.alias + " gets to go first for this round.")
if (enemy_battle_turn (self,enemy) = true) {
msg ("It is now your turn.")
}
}
on ready {
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
else {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
else if (GetInt (self,"spd") = GetInt (enemy,"spd")) {
if (RandomChance (50) = true) {
on ready {
msg ("You get to go first for this round")
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
}
on ready {
if (enemy_battle_turn (self,enemy) = true) {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
else {
on ready {
msg (enemy.alias + " gets to go first for this round.")
if (enemy_battle_turn (self,enemy) = true) {
msg ("It is now your turn.")
}
}
on ready {
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
else {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
}
}
else {
second_value = true
}
return (second_value)
]]></function>
<function name="self_battle_turn" parameters="self,enemy" type="boolean"><![CDATA[
third_value = false
msg (self.alias + " has " + self.cur_hp + " HP left.")
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
wait {
show menu ("What is your battle choice?", split ("Attack;Defend;Cast;Item;Run", ";"), false) {
switch (result) {
case ("Attack") {
fourth_value = false
if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"spd")) = true) {
msg (enemy.alias + "evaded your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"Dex") - GetInt (self,"agi")) = true) {
msg (enemy.alias + "parried your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"dex")) = true) {
msg (enemy.alias + "blocked your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (self,"dex") - GetInt (enemy,"spd")) = false) {
msg ("Your attack missed " + enemy.alias +"!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"pr") - GetInt (self,"hc")) = true) {
msg ("Your attack got resisted by " + enemy.alias +"!")
fourth_value = true
}
else if (fourth_value = false) {
if (self.defending = true and enemy.defending = true) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * 2 * GetInt (self,"pd") / 2 + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
self.defending = false
}
else if (self.defending = true and enemy.defending = false) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * 2 * GetInt (self,"pd") + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
self.defending = false
}
else if (self.defending = false and enemy.defending = true) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * GetInt (self,"pd") / 2 + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
}
else if (self.defending = false and enemy.defending = false) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * GetInt (self,"pd") + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
}
}
}
case ("Defend") {
if (self.defending = false) {
self.defending = true
}
}
case ("Cast") {
self.defending = false
}
case ("Item") {
self.defending = false
}
case ("Run") {
self.defending = false
}
}
if (GetInt (enemy,"cur_hp") > 0) {
if (RandomChance (GetInt (self,"spd") - GetInt (enemy,"spd")) = true) {
msg ("You get an extra battle turn!")
self_battle_turn (self,enemy)
}
else {
msg ("Your battle turn is over.")
third_value = false
}
}
else if (GetInt (enemy,"cur_hp") <= 0) {
msg (enemy.alias + " is dead.")
msg ("You have won the battle!")
enemy.defending = false
enemy.dead = true
third_value = true
wait {
ClearScreen
}
}
}
}
return (third_value)
]]></function>
<function name="enemy_battle_turn" parameters="self,enemy" type="boolean"><![CDATA[
fifth_value = false
msg (self.alias + " has " + self.cur_hp + " HP left.")
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
result = GetRandomInt (1,3)
switch (result) {
case (1) {
sixth_value = false
if (RandomChance (GetInt (self,"agi") - GetInt (enemy,"spd")) = true) {
msg ("You have evaded the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"dex") - GetInt (enemy,"agi")) = true) {
msg ("You have parried the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"agi") - GetInt (enemy,"dex")) = true) {
msg ("You have blocked the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (enemy,"dex") - GetInt (self,"spd")) = false) {
msg (enemy.alias +"'s attack missed!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"pr") - GetInt (enemy,"hc")) = true) {
msg ("You resisted the attack!")
sixth_value = true
}
else if (sixth_value = false) {
if (enemy.defending = true and self.defending = true) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * 2 * GetInt (enemy,"pd") / 2 + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
enemy.defending = false
}
else if (enemy.defending = true and self.defending = false) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * 2 * GetInt (enemy,"pd") + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
enemy.defending = false
}
else if (enemy.defending = false and self.defending = true) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * GetInt (enemy,"pd") / 2 + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
}
else if (enemy.defending = false and self.defending = false) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * GetInt (enemy,"pd") + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
}
}
}
case (2) {
if (enemy.defending = false) {
msg (enemy.alias + " has choosen to defend itself.")
enemy.defending = true
}
}
case (3) {
enemy.defending = false
msg ("Cast")
}
}
if (GetInt (self,"cur_hp") > 0) {
if (RandomChance (GetInt (enemy,"spd") - GetInt (self,"spd")) = true) {
msg (enemy.alias + " gets an extra battle turn!")
wait {
enemy_battle_turn (self,enemy)
}
}
else {
msg (enemy.alias + " 's battle turn is over.")
fifth_value = true
}
}
else if (GetInt (self,"cur_hp") <= 0) {
msg (self.alias + " has died.")
msg ("GAME OVER")
finish
}
return (fifth_value)
]]></function>
<function name="npc_reachable" parameters="object" type="boolean">
value = false
foreach (x,ScopeReachableNotHeld ()) {
if (x=object) {
value = true
}
}
return (value)
</function>
<function name="crit_hit" parameters="object" type="int">
if (RandomChance (GetInt (object,"luck")) = true) {
value = 2
}
else {
value = 1
}
return (value)
</function>
</asl>

Espera
I'd love to give you my whole game code, but I can't It's too huge to fit in a forum post. Whoever can address this is going to have to troubleshoot it with the code I've provided, or request specific other code.

Espera
I've checked to see if ti's an alias issue. I don't think it is. The problem comes up no matter what name I enter, including the test enemy's real name.

Espera
I found a way you can see my code. Have at it.

https://docs.google.com/document/d/1xtt0v0ibSv1AeMuUglZrI4V5iefsyI5gUqWiv6GuxN0/edit

HegemonKhan
I need to get permission to view file, sent a pm here on this site, to verify my email request for permission, as mine.

Espera
Try again. The link should work now. Sorry, this is my first time using googledocs.

jaynabonne
The problem is that all variables are lost within the script for a ShowMenu. When you call ShowMenu, you need to save those objects somewhere (e.g. in the game) so that you can reference them once the menu choice has been made.

if (HasAttribute(object, "enemy")) {
SetObjectFlagOn (object, "incombat")
game.current_object = object // Save current object for use in menu script.
ShowMenu ("What will you do? ", player.movelist, false) {
object = game.current_object // Restore current object
switch (result) {
case ("kick") {
player.damage = player.Fight - object.fightres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You kick "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
case ("Magic Bolt") {
player.damage = player.Magic - object.magicres
if (GetInt(player, "damage") = 0) {
player.damage = 0
}
object.hp = object.hp - player.damage
msg ("You focus your magic at your horn and fire a Magic Bolt at "+object.prefix+" "+object.name+" for "+player.damage+" damage!")
}
}
}
}


Espera
Thank you immensely, Jay.
Just to be clear, the current_object attribute i sa string?

jaynabonne
It's whatever is assigned to it. In this case, since it's the "object" parameter passed to the command, it's an actual object, the same as what you are using before the ShowMenu,

Espera
Thanks a buch! It's working.

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

Support

Forums