ID:143051
 
Code:
turf
Water
icon='turfs.dmi'
icon_state="water"
density=1
Click()
if(!usr.fishing)
usr.canmove=0
usr.fishing=1
usr.client.screen+=new/obj/HUD/Reel
//Fishing Algorithm!
usr << "You begin to fish."
var/Fish=rand(50,70)
sleep(Fish)
if(prob(65))
usr << "You feel a nudge! Reel!"
usr.Do_Reel_Click=1
spawn(50)
if(!usr.Did_Click)
usr << "The fish broke the line."
usr.fishing=0
usr.canmove=1
return
else
usr.Did_Click=0
while(usr.Reel_Clicked)
usr << "You reel in the line."
usr.Reel_Clicked=0
usr.Did_Click=1
usr.Do_Reel_Click=0
sleep(Fish)
usr << "The fish is getting weak, quick, reel!"
usr.Do_Reel_Click=1
spawn(50)
if(!usr.Did_Click)
usr << "The fish broke the line."
usr.canmove=1
usr.fishing=0
return
else
usr.Did_Click=0
while(usr.Reel_Clicked)
usr << "You caught a fish!"
usr.Do_Reel_Click=0
usr.Reel_Clicked=0
usr.Did_Click=1
usr.canmove=1
usr.contents += new/obj/Fish
usr.fishing=0
return
else
usr << "You didn't get a bite."
usr.fishing=0
return
else
usr << "You are already fishing."
return

obj
HUD
Reel
icon='Reel.PNG'
screen_loc="13,13"
Click()
if(usr.Do_Reel_Click)
usr.Reel_Clicked = 1
else
usr.Clicked_Early = 1

mob/var
canmove
fishing
Reel_Clicked
Do_Reel_Click
Clicked_Early
Did_Click


Problem description:
I'm working on a fishing code, and when I attempt to fish, it displays, "You begin to fish.", "You feel a nudge! Reel!", and "The fish broke the line."

This is all fine and well, assuming I didn't click the "Reel" button, which I did. Using Deadron's debugger, I checked my variables that are related to this fishing code.

Canmove = 1
Did_Click = null
Do_Reel_Click = 1
Reel_Clicked = 1

If you look at the Water Click() code, those variables show that it recognizes the "Reel" button being pressed, but the while statement didn't kick in to continue the job. I think the problem is that while will only try to execute once, and if the value is 0, it ceases to try.

The problem is though, I need a piece of code that is instantaneous, in a way that as soon as you click the "Reel" button, it starts to execute the code. I thought that is what while did.

My question I suppose is am I using while improperly? And if so, what should I use in place of while to get the desired effect?
If you want something instantaneous to happen then you're going to have to put that in another proc and call it from Reel/Click(). There's nothing you can reasonably put in turf/Water/Click() that will wait until something else is clicked and then immediately do something.

I will say that your whole system there is convoluted and excessive. KISS: Keep It Simple, Stupid. This is what I would do, brutally ripped from World of Warcraft:

var/list/fishies = list( \
/turf/water = list(/obj/item/fish=100, /obj/item/oldboot=10) \
)

obj/item/fish
obj/item/oldboot
obj/item/iron_ore

obj/bobber
icon = 'bobber.dmi'
var/obj/fish
var/bobbed = 0
var/mob/owner
New(var/turf/location, var/mob/owner, var/obj/fish, var/bobtime, var/reaction)
..()
src.fish = fish
fish.loc = src
src.owner = owner
pixel_x = rand(-16,16)
pixel_y = rand(-16,16)
spawn(bobtime) bob(reaction)
proc
bob(var/reaction)
flick("bob",src) //flick a bob, to indicate a fish is on the line
bobbed = 1
sleep(reaction)
owner << "The fish got away."
del(src)
Click()
if(usr != owner) return
if(!bobbed)
usr << "There was no fish on the line."
else
usr << "You caught a [fish]!"
Move(fish,usr)
del(src)

mob
var/obj/bobber/bobber
proc/Fish(var/turf/T)
if(T in oview(src,5))
if(bobber)
del(bobber)
var/list/fishtypelist = fishies[T.type]
var/fishtype
if(!fishtypelist) fishtype = /obj/item/iron_ore
else fishtype = pick(fishtypelist)
bobber = new(T, src, new fishtype(), bobtime = rand(50,100), reaction = 30)

turf/water
icon = 'turfs.dmi'
icon_state = "water"
Click()
usr.Fish(src)


Well, that actually ended up pretty long... but it's pretty complete, with the exception of data (which just goes into the global fishies list) and anything skill-related (which could go three ways: reduction of bobtime, increase in reaction, or a restriction on the Fish() proc being called from the water turfs).
In response to Garthor
I think I see what your getting at. It'll take me a little bit to fully get the code, but I can tell I was barking up the wrong tree with turf/water/Click(). =/

Thanks for your help!