ID:147446
 
I have a verb, which is meant to allow a player to choose one of his ships from port, and trade goods to and from it.

                verb
Trade()
set src in oview(1)
var/mob/Boats/A = new/mob/Boats()
TradeShipChoose(src,usr,A)
if(A)
var/B
world<<"[A]"
world<<"[A.Storage.len]"
SpaceCheck(A,usr,B)
world<<"[B] = B"
if(B)
usr<<"You have [B] spaces left on your ship."
switch(input(usr, "Do you want to buy goods, or sell them?","Trading Post") in list("Buy Goods","Sell Goods"))
if("Buy Goods")
BuyProc(src,usr,B,A)


The error is coming from TradeShipChoose. I have tried putting tests after it, to tell me the name of the ship, and they always give "Boats" even when that isn't the name of the ship! Here is my TradeShipChoose Proc:

    TradeShipChoose(turf/PORTS/TradingPosts/A,mob/B,mob/Boats/C)
var/list/L = new/list()
var/turf/PORTS/D
for(var/turf/PORTS/Z in world)
if(Z.island == A.island)
D = Z
if(D.Spaces)
for(C in D.Spaces)
if(C.Owner == B)
L.Add(C)
if(L)
if(L.len == 1)
C = L[1]
B << "We will be using your ship [C] for trading to and from."
else
C = input(B,"Which boat to you wish to use?","Boats") in L
B << "We will be using your ship [C] for trading to and from."
else
B<<"You have no boats!"
del(C)


Can anyone explain why the verb is ignoring what the proc should be doing? For the record, it still says "We will be using your ship [C] for trading to and from." anyway!

~Ease~
Please clarify. You haven't explained what the latter proc is supposed to do, or what exactly is happening in it that's not supposed to. (I know you think you did this, but you didn't; "the name of the ship" is kind of ambiguous in this context, and you weren't even clear on where that's being asked or what it's supposed to be.)

Lummox JR
In response to Lummox JR
Sorry about that. The Trade verb, as a whole is meant to:
Find the Port (Harbour) on the island, find the player's boat in that port, and if there are more than 1 let him choose which one he wants. Then it has to check if it has any storage space, if so then he can Buy or Sell Goods.

The proc is meant to:

    TradeShipChoose(turf/PORTS/TradingPosts/A,mob/B,mob/Boats/C)
var/list/L = new/list()
var/turf/PORTS/D
for(var/turf/PORTS/Z in world)
if(Z.island == A.island)
D = Z // Find the port on the same island
if(D.Spaces) //If it has any ships in it.
for(C in D.Spaces) //Loops through all of the ships
if(C.Owner == B) //If the ship belongs to the player, then add it to the list!
L.Add(C)
if(L)
if(L.len == 1)//If there was only one ship that belonged to the player...
C = L[1]
B << "We will be using your ship [C] for trading to and from."
else//If there was more than one, let them choose which one!
C = input(B,"Which boat to you wish to use?","Boats") in L
B << "We will be using your ship [C] for trading to and from."
else
B<<"You have no boats!"
del(C)


It is meant to select which /mob/Boats the player will be trading goods onto, and from! Is that a little more helpful?

~Ease~
In response to Ease
Ease wrote:
It is meant to select which /mob/Boats the player will be trading goods onto, and from! Is that a little more helpful?

Yes, but you still haven't explained what exactly is going wrong with this proc--only in the vague terms mentioned previously.

Lummox JR
In response to Lummox JR
Oops, sorry again. Well when the verb calls the proc
"var/mob/Boats/A = new/mob/Boats()
TradeShipChoose(src,usr,A)"

It is meant to create a boat, then the proc is meant to set the boat to one of the players boats. The tests inside the proc show that it is setting A to the right boat, but all tests in the verb after the proc, show that the boat has been changed at all, and is just a neutral "/mob/Boats" , not the boat that was selected in proc. So affectively the verb is ignoring the proc!

~Ease~
Try this:
verb
Trade()
set src in oview(1)
var/mob/Boats/A = TradeShipChoose(src,usr)
if(A)
var/B
world<<"[A]"
world<<"[A.Storage.len]"
SpaceCheck(A,usr,B)
world<<"[B] = B"
if(B)
usr<<"You have [B] spaces left on your ship."
switch(input(usr, "Do you want to buy goods, or sell them?","Trading Post") in list("Buy Goods","Sell Goods"))
if("Buy Goods")
BuyProc(src,usr,B,A)




TradeShipChoose(turf/PORTS/TradingPosts/A,mob/B)
var/mob/boats/UseMe
var/list/L = new/list()
var/turf/PORTS/D
for(var/turf/PORTS/Z in world)
if(Z.island == A.island)
D = Z
if(D.Spaces)
for(var/mob/boats/C in D.Spaces)
if(C.Owner == B)
L.Add(C)
if(L)
if(L.len == 1)
UseMe = L[1]
B << "We will be using your ship [UseMe] for trading to and from."
else
UseMe = input(B,"Which boat to you wish to use?","Boats") in L
B << "We will be using your ship [UseMe] for trading to and from."
else
B<<"You have no boats!"
return UseMe
In response to Flick
Thank you so much Flick! Not only have you made my code work, but you have just taught me a major lesson in coding! I always thought that return was only for ending procs, and using in procs to be used inside "if". But now I know it's other uses! Thank you!

~Ease~