ID:146289
 
Code:
mob
var
mob/shopkeeper/shopkeeper


client/Topic(href,href_list[])
var/item_type = href_list["type"]
if(item_type)
var/obj/i = new item_type()
if(usr.zenni >= i.cost)
usr << "Enjoy your new item!"
usr.zenni -= i.cost
i.Move(usr)
usr.shopkeeper:Shopkeeper2()
else
usr << "Sorry you dont have enough money!"
usr.shopkeeper:Shopkeeper2()
mob
shopkeeper
Shopkeeper2
name = "-NPC- Shopkeeper"
icon = 'New Human.dmi'
icon_state = "person"
var/html
verb
Buy()
set src in oview(1)
usr.shopkeeper = src
Shopkeeper2(usr)

proc
Shopkeeper2()
html = {"
<style>
body{background:#C0C0C0}
</style>
<b>Welcome to my shop!</b>
<p>Here we supply all of the needs for the modern player!</p>
<table border = "3" cellspacing = "1" cellpadding = "1">
<Caption>Items</Caption>
"}

for(var/obj/A in src.contents)
html += {"
<tr><td align = "center">
[A.name]</td>
<td align = "center">Price : $
[A.cost]</td>
<td align = "center"><a href='?src=\ref
[usr];type=[A.type];action=buy'>Get</a></td>
</tr>
"}

usr << browse(html)

New()
src.contents += list(new /obj/items/Sword,new /obj/items/Gi,new /obj/items/Glasses)


Problem description:
This is what I'm using as a shopkeeper code.

BUT, when I run the game, I get frozen at the Login Screen.

(I'm using Deadrons Character Handling)

Any way I could modify this to go around that problem?

I tried turning
client/Topic(href,href_list[])
into
client/h/Topic(href,href_list[])


but when I run the game I can access the Shopkeeper, but I cannot buy anything. Suggestions?
client/Topic(href,href_list[])
if(href_list["type"])
var/item_type=href_list["type"]
var/obj/i = new item_type()
if(usr.zenni >= i.cost)
usr << "Enjoy your new item!"
usr.zenni -= i.cost
i.Move(usr)
usr.shopkeeper:Shopkeeper2()
else
usr << "Sorry you dont have enough money!"
usr.shopkeeper:Shopkeeper2()
else ..()


Try that. You were overwriting client/Topic(). To prevent that, use ..() or .=..() . I'm not exactly sure what the difference is between the two, but one is longer. Use it at the beggining of client/Topic(), or in an else statement at the end. By the way, use it in both client/Topic() procs you have, or better yet, combine them. If you are using a link, set a reference to the src, hopefully it a mob proc? Then just use mpb/Topic() to access the link. If I were use, I'd only use client/Topic() for forms.
There are a few things that you can change that would cut down on errors and provide better, more robust, and cleaner code.

  • Remove your usr abuse. In the immortal words of Lummox JR, Ungh.
  • In your Topic() proc, you should use type casting to remove your colons and usr. usr should be client.mob, or in this case src.mob, and type cast client.mob.shopkeeper. If you don't know how to do this there are many forum posts about it.
  • You forgot the parent (..()) in you shopkeepers New(). (This is probably what's causing your blank screen upon login.)
  • The variable html does not need to be defined as the mob's variable, just define it in the Shopkeeper2() proc.
In response to CaptFalcon33035
There are three ways that I know of to use the parent proc.

  • ..()
  • . = ..()
    
    At the end of every proc invisible to us is
    return .
    
    . So this will call the ..() proc upon returning.
  • return ..()
    
    This does the same as above and calls the ..() proc at when it returns.
In response to CaptFalcon33035
Thanks. It works now!
In response to Polaris8920
Just to clear up some possible confusion, . and ..() have nothing to do with each other. Well, nothing more than var/var1 and "value" have to do with each other.
You can set . to anything. It works just like a normal var attached to the proc/verb, except that unless you tell it otherwise the proc/verb will return the value of .

Now ..() will just do the parent version of the proc. It works just like any other proc.


The most common uses for . and ..() are . = ..() and return ..(), but it's important to realize that they aren't the only uses for it and that . and ..() aren't magic.



Also, you said "So this will call the ..() proc upon returning", and that's not true. I'm not sure if it's just a typo, but this wont call anything. ..() has already been called and . was set to ..()'s return value.


Here's an example that might help out.
mob/Move()
. = ..()
if(.)
src << "You took a step!"


Now what will happen here is:
-The default Move() proc is called, and it's value is returned to . So by default the player will either move or not move when Move() is called, depending on if the path is clear.
-If the default Move() was successful (meaning ..() returned 1, and thus . == 1), then it will tell us we've taken a step.
-Now since I didn't tell it to return, but the proc finished naturally, Move() will return the value of .
In response to DarkView
Yes, thanks for clearing it up. It's quite late here, and I must really get to bed.