ID:145501
 
Code:
mob/Build/verb/
Build()
var/list/buildlist=list()
for(var/obj/furniture/s) if(s.woodreq) if(usr.wood>=s.woodreq)
buildlist.Add(s)
usr<<"added"
if(!buildlist.len) usr<<"nope";return
var/item=input("What do you wish to build?","Build") in buildlist
var/obj/a = new item(usr.loc)
if(a.dirs)
var/b=input("What direction should it face?","Build") in list("North","East","South","West")
a.icon_state="[a][b]"
usr.wood-=a.woodreq
a.owner=usr
buildlist=list()


Problem description: The .len is always false (null), though I have objects and yes, they have a woodreq, and yes I have a heck a lot of wood, so I have no clue what the hell is happening.

I'm not sure but this might be the mistake:
if(!buildlist.len) usr<<"nope";return

That's the same as:
if(!buildlist.len) usr<<"nope"
return

You need to use those brackets, if you want to put it in one line:
if(!buildlist.len) {usr<<"nope";return}
In response to CIB
Fixed it, nvm..
One thing you need to do is add "as null|anything" after your input() statements, so there's a cancel option. Not including a cancel option is Incredibly Heinous Practice.

Lummox JR
In response to Lummox JR
I always do those in the end, after I revise the code. I never think about those when actually coding it. Anyway, I find the cancel button more annoying if anything, because when the value which is entered is false, you sometimes need to switch it to a true value. And then when they clicked 'Cancel', they'd get a true value. Utterly annoying.
In response to Mysame
Mysame wrote:
I always do those in the end, after I revise the code. I never think about those when actually coding it.

Not a good idea. Accounting for a cancel also allows you to deal with cases where the player logs out.

Anyway, I find the cancel button more annoying if anything, because when the value which is entered is false, you sometimes need to switch it to a true value.

The value entered is false only if it's a blank string, 0, or null (cancel).

And then when they clicked 'Cancel', they'd get a true value. Utterly annoying.

Um, no they don't. You must be doing something terribly wrong.

Lummox JR
In response to Lummox JR
Lummox, let me say what.. I said o.o
mob/admin/verb/Reboot()
var/a=input("Reboot in how many seconds?") as null|num
if(!a) a=1
world<<"Rebooting in [a] seconds"
sleep(a)
world.Reboot()


See? They'd get a TRUE value when canceling.
In response to Mysame
The "Cancel" option given by null|(whatever) returns null. If you check for it afterward you know they clicked cancel (or logged out).

mob/admin/verb/Reboot()
var/a=input("Reboot in how many seconds?") as null|num
if(a == null) return
else if(!a) a=1
world<<"Rebooting in [a] seconds"
sleep(a)
world.Reboot()


A false value for a numerical input can only be 0, and a false value for a string input can only be ""; the "not" operator is too generic to be relied upon when null is possible.
In response to Mysame
Mysame wrote:
Lummox, let me say what.. I said o.o
> mob/admin/verb/Reboot()
> var/a=input("Reboot in how many seconds?") as null|num
> if(!a) a=1
> world<<"Rebooting in [a] seconds"
> sleep(a)
> world.Reboot()

See? They'd get a TRUE value when canceling.

No. If they cancelled, a would be null. The reason YOU'RE getting a true value is because you're doing this:

Pick a.
If a is false, make a true.
Reboot in a seconds.

So obviously, a will always be true in that situation. But by pressing cancel, it comes out as null/false.
In response to Mobius Evalon
Aaaah! That's a new one. Thanks Mobius o.o
In response to Mysame
Mysame wrote:
Lummox, let me say what.. I said o.o
> mob/admin/verb/Reboot()
> var/a=input("Reboot in how many seconds?") as null|num
> if(!a) a=1
> world<<"Rebooting in [a] seconds"
> sleep(a)
> world.Reboot()

See? They'd get a TRUE value when canceling.

That's because you just overrode their null value with that silly if(!a) line.

Of course, you're also not rounding off, nor checking for negative values, nor multiplying by 10 to change seconds to ticks for sleep(). So really, nothing about that code is right.

Lummox JR
In response to Lummox JR
its still a bit off but it has a working cancel now

            Reboot()
set category = "Admin"
var/a=input("In How Many Seconds")as null|num
if (!a) return
world<<"Rebooting in [a] seconds"
sleep(a)
world.Reboot()
In response to Mxjerrett
It's off because you didn't actually read my post that you replied to. Using Mysame's code as-is is generally a bad idea. At this point he's in about the same boat you are.

Lummox JR
In response to DeathAwaitsU
DeathAwaitsU wrote:
> > mob/admin/verb/Reboot()
> > var/a=input("Reboot in how many seconds?") as null|num
> > if(!a) a=1
> > world<<"Rebooting in [a] seconds"
> > sleep(a)
> > world.Reboot()

Pick a.
If a is false, make a true.
Reboot in a seconds.

Just a bit of criticism: It's not "a seconds," it's "a/10 seconds."

Hiead
In response to Hiead
I forgot the ticks, but besides that Mobius his code is right, you know. It canels when you press.. cancel, and it changes to 1 when the num entered is 0.
In response to Mysame


put at the top of page
var/reboot=0


put under the admin part


            Reboot(var/a as num)        // This makes a delayed reboot.
set category="Admin"
if(a!=abs(a)||a>1000) return
if(reboot==0) reboot(a)
else reboot=0


Put at the bottom of the page

proc/reboot(var/a=30)
reboot=1
world<<"<font color=Red><font size=3><b>Game is rebooting in [a] seconds."
for(var/X=1,X<a,X++)
if(reboot==0)
world<<"<font color=Red><font size=3><b>Game reboot halted."
return
sleep(10)
world<<"<font color=Red><font size=3><b>Game is now rebooting."
world.Reboot()



here is a code i fixed up from a demo i found
In response to Mxjerrett
Um, that's not so much fixed. That demo must have been pure garbage. Best to stick to demos and libraries written by good programmers, and learn from those. Best also not to bring up a thread that's been settled for 3 days for... well, that.

Lummox JR