ID:150175
 
I'm having all kinds of problems with my huge project, and when ever I try to do something compelx with IF or else IF or even Switch statements my code just goes to hell..

Anyone have a good suggestion??? Also I need some mentoring on Augmenting List between saw TURF/OBJ/MOBs

LJR
LordJR wrote:
I'm having all kinds of problems with my huge project, and when ever I try to do something compelx with IF or else IF or even Switch statements my code just goes to hell..

Could you show us the if statements that are giving you trouble? One parenthesis out of place or a || that should be && cna lead to very unexpected results.

Order of operations is one of the most common logic errors in if statements. One of the things that confused me when I began was the in operator in an if statement. Something like

if(likes_cheese_flag && "cheese" in grocerylist)

would not work properly. It ANDs likes_cheese_flag with "cheese", and "cheese" is always true. I had to put parenthesis around the in block

if(likes_cheese_flag && ("cheese" in grocerylist))


Also I need some mentoring on Augmenting List between saw TURF/OBJ/MOBs

I don't understand what you are asking for. Could you elaborate?
In response to Shadowdarke
LordJR was up for three days straight with very little to eat, (programming Kemet) so if this post sounds a bit psychotic, that's probably the reason...
In response to Xooxer
Xooxer wrote:
LordJR was up for three days straight with very little to eat, (programming Kemet) so if this post sounds a bit psychotic, that's probably the reason...

;) Aye, that I was.. and plan to slave over Kemet some more in the coming days, all I ask if for people to know there is more than the Halls of Creation when you first enter the game. Try to make your way to earth before casting judgement on the game or just loggin out.

LJR
Ok I can't even get this if statement to work to buy this item. Also the reason I've got it as a proc and not verb, is because an Area in within 2 tiles of the add +verb.Buy()

proc/Buy(mob/pc/M as mob in oview(2))
var/list/tanis_ashop = list("Common Shield (55gp)")
var/help_text = "Choose which armor fits your needs?"
var/prompt_title = "Tanis Armor Shop"
var/armorp = input(help_text, prompt_title) in tanis_ashop
if((armorp == "Common Shield (55gp)") && (M.gold > 54))
M.gold -= 55
.. rest of code continues here...

LJR
In response to LordJR
LordJR wrote:
Ok I can't even get this if statement to work to buy this item. Also the reason I've got it as a proc and not verb, is because an Area in within 2 tiles of the add +verb.Buy()

Well, you could use
set src in view(2)
to make it a verb that someone can use from within two steps of the object. That wasn't your problem though, so on to the that.

proc/Buy(mob/pc/M as mob in oview(2))
var/list/tanis_ashop = list("Common Shield (55gp)")
var/help_text = "Choose which armor fits your needs?"
var/prompt_title = "Tanis Armor Shop"
var/armorp = input(help_text, prompt_title) in tanis_ashop
if((armorp == "Common Shield (55gp)") && (M.gold > 54))
M.gold -= 55
.. rest of code continues here...

Your if() seems fine. You may want to place some debugging lines in there so you can see what data it is working with:

world.log << "[M] is shoping at the Tanis Armor shop."
var/armorp = input(help_text, prompt_title) in tanis_ashop
world.log << "[M] selected [armorp] and has [M.gold] gold."
if((armorp == "Common Shield (55gp)") && (M.gold > 54))
world.log << "Now inside the Common Shield if() block."
M.gold -= 55

after you locate the source of the trouble, just comment out the debug messages or erase them entirely.
In response to Shadowdarke
Your if() seems fine. You may want to place some debugging lines in there so you can see what data it is working with:

world.log << "[M] is shoping at the Tanis Armor shop."
var/armorp = input(help_text, prompt_title) in tanis_ashop
world.log << "[M] selected [armorp] and has [M.gold] gold."
if((armorp == "Common Shield (55gp)") && (M.gold > 54))
world.log << "Now inside the Common Shield if() block."
M.gold -= 55

after you locate the source of the trouble, just comment out the debug messages or erase them entirely.

Yeah I did, and this is what it gave me, why is it showing up as the npc and not the pc??

Undefined variable /mob/npc/armor_shopkeeper/var/gold.
proc name: Buy (/mob/npc/armor_shopkeeper/proc/Buy)
source file: npc.dm,82
usr: LJR (/mob/pc/male)
src: LJR (/mob/pc/male)
call stack:
LJR (/mob/pc/male): Buy(Hotep the Armorer (/mob/npc/armor_shopkeeper))
In response to LordJR
LordJR wrote:
why is it showing up as the npc and not the pc??

Because of this line:
proc/Buy(mob/pc/M as mob in oview(2))

mob/pc/M should force it to be a pc, but I think the "as mob" is confusing it into accepting any mob and treating it as if it were a /mob/pc.

The real trouble is "oview(2)". Since you don't specify the center, it defaults to usr. oview() doesn't include the center, so when you use Buy(), it lets you select a mob from within 2 spaces, not including the usr!

Instead of doing it this way, make Buy() a shopkeeper verb with no arguments and use set src in oview(2) to allow people to use it up to 2 spaces away.

In the beginning of the proc, make sure usr is a pc mob, then declare M as a /mob/pc and assign usr to it so you can use all the pc vars on it.

verb/Buy()
set src in oview(2)
if(!istype(usr,/mob/pc))
usr << "Silly npc, verbs are for players."
return
var/mob/pc/M = usr
// ... the rest of the code goes here.
In response to Shadowdarke
Yeah I had it as a verb before, but WOW man!!
What you just showed me is gonna help alot!!!

Thank you sooooooooooooooo much!!!!!!

LJR
In response to LordJR
I'm very glad I could help. I look forward to playing Kemet when it's finished ;)
In response to LordJR
LordJR wrote:
Ok I can't even get this if statement to work to buy this item. Also the reason I've got it as a proc and not verb, is because an Area in within 2 tiles of the add +verb.Buy()

proc/Buy(mob/pc/M as mob in oview(2))
var/list/tanis_ashop = list("Common Shield (55gp)")
var/help_text = "Choose which armor fits your needs?"
var/prompt_title = "Tanis Armor Shop"
var/armorp = input(help_text, prompt_title) in tanis_ashop
if((armorp == "Common Shield (55gp)") && (M.gold > 54))
M.gold -= 55
.. rest of code continues here...

This seems like a very inefficient way to code a shopkeeper; I can see why you titled this thread the way you did! Those ifs must be a nightmare to code. I've got some code that could help you a lot, though it's not quite ready for its "debut".

To give you a push in the right direction, though, here's what you need to do: Make an associative list.
  var/list/selling

New()
..()
selling=list((new /obj/shield/common)=55, ... )

You see, each item in the list is an object with an associated price. In your Buy proc, the list that goes into input() should be set up then, from the items in selling. When you pick an item, check the price, then create a new one of the same type. This form of shopkeeper code is much simpler and won't lead you through a complicated mess of switches or ifs.

Lummox JR