Help with Debugging

HegemonKhan
19 Jan 2014, 04:18
in trying to help Omega with:

Omega wrote:Also thanks for the codes for shopping. I did find these out but didn't help much so I just made it simple. I wanted something like:


>Welcome to my shop
1.Red potion
2.Blue potion

(player chooses one)

>(red potion) that one heals you.

(but deals with money(rupees) so:)
clicking on red potion should subtract 10 rupees from the players inventory.


I'm trying to craft my own advanced "shopping" code system for him~her:

<asl version="540">
<include ref="English.aslx"/>
<include ref="Core.aslx"/>
<game name="Testing Game Stuff">
<gameid>d67ec73f-f879-4911-9d88-c02ea527c534</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="rupees" type="int">0</attr>
<attr name="hit_points" type="string">999/999</attr>
<attr name="current_hit_points" type="int">999</attr>
<attr name="maximum_hit_points" type="int">999</attr>
<attr name="changedcurrent_hit_points" type="script"><![CDATA[
if (player.current_hit_points <= 0) {
msg ("You have died.")
msg ("GAME OVER")
finish
}
if (player.current_hit_points > player.maximum_hit_points) {
player.current_hit_points = player.maximum_hit_points
}
player.hit_points = "HP: " + player.current_hit_points + "/" + player.maximum_hit_points
]]></attr>
<attr name="changedmaximum_hit_points" type="script">
player.hit_points = "HP: " + player.current_hit_points + "/" + player.maximum_hit_points
</attr>
<attr name="mana_points" type="string">99/99</attr>
<attr name="current_mana_points" type="int">99</attr>
<attr name="maximum_mana_points" type="int">99</attr>
<attr name="changedcurrent_mana_points" type="script"><![CDATA[
if (player.current_mana_points > player.maximum_mana_points) {
player.current_mana_points = player.maximum_mana_points
}
player.mana_points = "MP: " + player.current_mana_points + "/" + player.maximum_mana_points
]]></attr>
<attr name="changedmaximum_hit_points" type="script">
player.mana_points = "MP: " + player.current_mana_points + "/" + player.maximum_mana_points
</attr>
<attr name="statusattributes" type="simplestringdictionary">hit_points = !;mana_points = !</attr>
</object>
</object>
<object name="shop_room">
<inherit name="editor_room" />
<alias>shop</alias>
<object name="shop_owner">
<inherit name="editor_object" />
<alias>shop owner</alias>
<attr name="rupees" type="int">0</attr>
<attr name="inventory_object_list" type="simpleobjectlist">red_potion;blue_potion</attr>
<attr name="shop" type="script"><![CDATA[
msg ("(1) Peruse, (2) Buy, or (3) Sell")
msg ("")
get input {
if (IsInt (result) = false) {
msg ("Please type in the number of your choice next time.")
} else if (IsInt (result) = true) {
if (ToInt (result) < 1 and ToInt (result) > 3) {
msg ("Please type in one of the correct numbers of your choice next time.")
} else if (ToInt (result) > 0 and ToInt (result) < 4) {
msg ("Here's the items that I have in stock:")
msg ("")
x = 0
foreach (item_x, shop_owner.inventory_object_list) {
x = x + 1
msg (x + ". " + item_x.alias)
}
switch (result) {
case ("1") {
msg ("")
msg ("What item would you like to know about?")
msg ("")
get input {
if (IsInt (result) = false) {
msg ("Please type in the number of your choice next time.")
} else if (IsInt (result) = true) {
if (ToInt (result) < 1 and ToInt (result) > ListCount (shop_owner.inventory_object_list)) {
msg ("Please type in one of the correct numbers of your choice next time.")
} else if (ToInt (result) > 0 and ToInt (result) <= ListCount (shop_owner.inventory_object_list)) {
invoke (ScriptDictionaryItem (global_data_object.item_script_dictionary, result)
}
}
}
}
case ("2") {
msg ("")
msg ("What item would you like to buy?")
msg ("")
get input {
result_x = result
if (IsInt (result_x) = false) {
msg ("Please type in the number of your choice next time.")
} else if (IsInt (result_x) = true) {
if (ToInt (result_x) < 1 and ToInt (result_x) > ListCount (shop_owner.inventory_object_list)) {
msg ("Please type in one of the correct numbers of your choice next time.")
} else if (ToInt (result_x) > 0 and ToInt (result_x) <= ListCount (shop_owner.inventory_object_list)) {
msg ("How much of this item would you like to buy?")
item_xx = ObjectListItem (shop_owner.inventory_object_list, ToInt (result_x) - 1)
foreach (item_xxx, ScopeInventory()) {
if (item_xxx.alias = item_xx.alias) {
quantity_x = item_xxx.quantity
} else {
quantity_x = ToInt (1)
}
}
msg ("You can buy 1 through " + ToString (99 - quantity_x) + item_xx.alias + "s.")
get input {
result_xx = result
if (IsInt (result_xx) = false) {
msg ("Please type in the number of your choice next time.")
} else if (IsInt (result_xx) = true) {
if (ToInt (result_xx) < 1 and ToInt (result_xx) > 99 - quantity_x) {
msg ("Please type in one of the correct numbers of your choice next time.")
} else if (ToInt (result_xx) > 0 and ToInt (result_xx) <= 99 - quantity_x) {
if (player.rupees < ToInt (result_xx) * item_xx.rupees) {
msg ("You don't have enough rupees")
} else if (player.rupees >= ToInt (result_xx) * item_xx.rupees) {
foreach (item_xxxx, ScopeInventory()) {
if (item_xxxx.alias = item_xx.alias) {
item_xxxx.quantity = item_xxxx.quantity + ToInt (result_xx)
player.rupees = player.rupees - (ToInt (result_xx) * item_xx.rupees)
shop_owner.rupees = shop_owner.rupees + (ToInt (result_xx) * item_xx.rupees)
} else {
CloneObjectAndMove (item_xx, player)
foreach (item_xxxxx, ScopeInventory()) {
if (item_xxxxx.alias = item_xx.alias) {
item_xxxxx.quantity = item_xxxxx.quantity + ToInt (result_xx)
player.rupees = player.rupees - (ToInt (result_xx) * item_xx.rupees)
shop_owner.rupees = shop_owner.rupees + (ToInt (result_xx) * item_xx.rupees)
}
}
}
}
}
}
}
}
}
}
}
}
case ("3") {
}
}
}
}
}
]]></attr>
<attr name="displayverbs" type="listextend">Shop</attr>
</object>
</object>
<object name="global_data_object">
<inherit name="editor_object" />
<object name="red_potion">
<inherit name="editor_object" />
<alias>red potion</alias>
<attr name="quantity" type="int">1</attr>
<attr name="rupees" type="int">10</attr>
<attr name="changedquantity" type="script">
if (this.quantity = 0) {
destroy (this.name)
}
</attr>
<attr name="drink" type="script">
player.current_hit_points = player.current_hit_points + 200
msg ("You drink the red potion, restoring 200 HP.")
this.quantity = this.quantity - 1
</attr>
<attr name="inventoryverbs" type="listextend">Drink</attr>
</object>
<object name="blue_potion">
<inherit name="editor_object" />
<alias>blue potion</alias>
<attr name="quantity" type="int">1</attr>
<attr name="rupees" type="int">50</attr>
<attr name="changedquantity" type="script">
if (this.quantity = 0) {
destroy (this.name)
}
</attr>
<attr name="drink" type="script">
player.current_mana_points = player.current_mana_points + 20
msg ("You drink the blue potion, restoring 20 MP.")
this.quantity = this.quantity - 1
</attr>
<attr name="inventoryverbs" type="listextend">Drink</attr>
</object>
<attr name="item_script_dictionary" type="scriptdictionary">
<item key="1">
msg ("Effect: restores 200 HP")
msg ("Buy Price: 10 rupees")
msg ("Sell Price: 5 rupees")
</item>
<item key="2">
msg ("Effect: restores 20 MP")
msg ("Buy Price: 50 rupees")
msg ("Sell Price: 25 rupees")
</item>
</attr>
</object>
<verb>
<property>shop</property>
<pattern>shop</pattern>
<defaultexpression>"You can't shop here."</defaultexpression>
</verb>
<verb>
<property>drink</property>
<pattern>drink</pattern>
<defaultexpression>"You can't drink this thing."</defaultexpression>
</verb>
</asl>


but, in going to troubleshoot (in seeing if it even remotely miraculously works), I've got a game loading troubleshooting problem (so, I can't even work on troubleshooting all the other probable errors in my attempt at coding this stuff, argh):

Failed to load game due to the following errors:
*Error: An item with the same key has already been added.

and I'm not able to figure out the cause of this error,

so would anyone want to try to help me with finding this error?

(or, just look over my code in general, of whether it would work or not, and if not, then the game load error doesn't matter, but if my code can work, then we'll need to fix the game loading error)

(this is my first time attempting to code an "advanced ~ for me" shopping system on my own, aka without using Pixie's Shop Library code)

(good programmers beware, as you'll be cringing at my flailing first attempt at coding something at this level, as it's really ugly coding, lol)

thanks,
HK

jaynabonne
19 Jan 2014, 10:55
You have two attributes on the player named "changedmaximum_hit_points". Looking at it, I think you want the second one to be named "changedmaximum_mana_points". (Just a guess...)

HegemonKhan
19 Jan 2014, 12:49
wow, thanks jayna, finding a needle in a haystack, laughs.

a stupid mistake... forgot to check my "changed" scripts (copy and paste error by me most likely ~ didn't change the "hit" to "mana" after copying and pasting... argh)

--------

now, hopefully I can load into my game... and troubleshoot whatever problems I have from there... (or, I still have other troubleshooting with the game load up still... we'll see...)

jaynabonne
19 Jan 2014, 13:09
I found it by deleting text out of the file until it loaded and then adding text back until it failed, deleting other bits, etc. I didn't see it right away myself. :) But it was straightforward to narrow it down a piece at a time. If that helps for the future...

HegemonKhan
19 Jan 2014, 19:34
I've used that trick too... it's a bit of a pain though... as I have to make sure I've got a backup (and don't save over that backup, lol), and to keep them separate, cutting and pasting out code, and then pasting back in code. It's just a hassle...
(sorry that you had to do this... I was just hoping that with more eyes on the code, someone would just spot it from a mere glance over the code, as I know how difficult it can be to find~identify an error and then to fix it, especially with someone else's code that you're unfamiliar with ~ though this can make spotting the error easier ~ due to how the brain skips errors with things that it is familiar with ~ it's hard to "proofread" your own written school papers or computers codings ~ Brain Games on Discovery channel is such an awesome show, hehe).

Can you find the
the error in this?

(I forgot the exact text that the show used... meh, so this probably won't trick your brain at all, lol)

george
19 Jan 2014, 21:50
HK, now that you're this far along in your coding adventure, you should think about using version control.

HegemonKhan
19 Jan 2014, 22:03
what do you mean by that? I'm not familiar with "version control"... my apologies. (does it mean, documenting~organizing my versions~updates of my practice codings ~ testing games?)

george
19 Jan 2014, 22:14
Version control is a kind of software you use to help with your projects, just Google and you'll see.

HegemonKhan
20 Jan 2014, 04:54
ah cool, awesome, hehe. I'll definately look into using it. thanks George!