ID:165467
 
I fall upon the mercy of my betters in this. I am a complete noob, though i have taken the time to go through many of the tutorials as well as the DM guide and Reference.

What I am attempting to do is to write a simple game to help be apply what I have read to the program. I want to make a verb [(Light) in this case] that checks a variable of an obj (fire/lit) for an if/else for either lighting a fire, to reporting back to the usr.

Code:
//****TEST TEST TEST TEST TEST TEST****//
fire
icon = 'fire.dmi'
var
lit = 0
fireplace_1
fireplace
icon = 'fireplace.dmi'
icon_state = "fireplace1"
density = 1
verb
Light(obj/O as obj in view(1))// verb to light fires
if(/fire/lit <= 0)//error(A)
view() << "[usr] starts a cozy fire."
obj/fire = new(6,17,1)//error(B)
obj/fire/lit += 1//error(C)
else
usr << "There is already a fire lit!"
chimney
icon = 'fireplace.dmi'
icon_state = "chimney1"
//****TEST TEST TEST TEST TEST TEST****//

Errors:
tavernworld.dm:107:error:/fire/lit:undefined type path//(A)
tavernworld.dm:109:error:obj/fire:undefined var//(B)
tavernworld.dm:110:error:obj/fire/lit:undefined var//(C)

What i WANT is for a usr within 1 place to be able to light a fire in the fireplace using "light" as a verb.

Could someone please point me in the correct direction to learn what I am doing wrong?

((ps. if it matters at all, the fireplace is two icons))
Re-read the DM Guide and general DM tutorials.

Also, post your code between DM tags on the forum (like this:).
code goes here
In response to Kaioken
thanks
In response to Cuddlebear
Do read guides and tutorials, but I will explain the specific problems in your posted code here.

You are trying to access an object's variable by using its type path or something. That is incorrect. Look up the '.' operator in the DM Reference (press F1 in Dream Maker). THAT is the way you access objects' variables and procs.

Another problem is your usage of 'new'. You specify coordinates, but you have to specify a /turf location. The locate() proc (look it up too) can return a turf of specified coordinates.
Your final problem is, if I understand what you are trying to do here, is that you need to typecast the O argument as of type obj/fire, not /obj.

Also, since the 'lit' var can either be 0 or 1, use boolean checks on it, not the == , <= , != etc operators. Read more here: http://bwicki.byond.com/ByondBwicki.dmb?TrueFalse

Here is your code fixed:
                Light(obj/fire/O in view(1))// verb to light fires
if(O.lit)//error(A) // use . operator, use boolean check
view() << "[usr] starts a cozy fire."
obj/fire/F = new(locate(6,17,1))/*error(B) //use locate()...but you will
probably want a dynamic location, not a predefined one?
also, typecast this as /obj/fire, not /obj, and name this var 'F'*/

F.lit = 1//error(C) //use . operator
else
usr << "There is already a lit fire!"


I think that should work. I posted this extra post because you seem like a cool guy that wants to learn, rather than requesting people to solve problems for you. :)
In response to Kaioken
Thanks! i really appriciate that you took the time to explain what i was doing wrong. The fixed code is icing on the cake. looking at your code vs mine, it was easy to see where i made my mistakes. Rest assured that i AM in the process of re-reading the guide, but i can't tell you how much it helps solidify the learning by being shown where i bumbled up.
In response to Cuddlebear
No problem. We are willing to help those who are truly willing to learn.
In response to Kaioken
i hate to trouble you again, but i've found myself in a bit of a coding pickle. Before i start, i've gotten through the first 7 chap's of the guide again (i've found that having done a few tutorials has helped me relate to the reading better a 2nd time), but i can't figure how to relate this to anything written down.

point is, i've reached my first run-time error, and i don't know how to fix it.

With Kaioken's wonderful help, i managed to make a fire place that a mob can go up to and light a fire, then put one out.
obj
fire
icon = 'fire.dmi'
verb/put_out(obj/fire/F in view(1))
set src in view(1)
del(src)


fireplace
icon = 'fireplace.dmi'
density = 1
var
lit=0
verb/light(obj/fireplace/O in view(1))
set src in view(1)
if(src.lit<=0)
var/obj/fire/F = new(loc)
lit+=1
world << "[usr] starts a cozy fire."
else
usr << "There is already a fire lit here."
verb/put_out(obj/fire/F in view(1))
set src in view(1)
if (lit >= 1)
del(F)
lit -= 1
world << "[usr] extinguishes a fire."
else
usr << "There isn't a fire here."
chimney
icon = 'chimney.dmi'


the error is that the put_out verb will delete the fireplace itself if used w/o a fire present.

edit: i am also getting this warning (but not error)
41:F :warning: variable defined but not used

i don't know how to proceed. Should i add the obj/fire under the fireplace parent? Should i put the put_out verb under fire? If i do, how would i get it to check and change the fireplace.lit var?

Also, is there a way to have a verb "disappear" after it's been used? I mean as in my fireplace, after lit has been used and a fire is made, how do i make the verb disappear until the fire is put out? Why when i use the lit verb more than once, it wants me to choose between fire and fireplace?

i know my problem must be with having two objects in one place and using del(), because i also have windows in the lil house now that i can make open and close! (^_^ so proud of myself!)
    window
icon = 'window.dmi'
icon_state = "window_open"
var
open = 0
verb/close(obj/window/W in view(1))
set src in view(1)
if(src.open <= 0)
view() << "[usr] closes the window."
icon_state = "window_close"
open += 1
else
usr << "This window is already closed."
verb/open(obj/window/W in view(1))
set src in view(1)
if(open >= 1)
view() << "[usr] opens the window."
icon_state = "window_open"
open -= 1
else
usr << "This window is already open."



and finally, two more noob questions:
1) Is there an irc chat for Byond?
2) How do I get a avatar to go next to my forum name? ( i cam't find an option in "preferences".)
In response to Cuddlebear
Kaioken (me) wrote:
Also, since the 'lit' var should either be 0 or 1, use boolean checks on it, not the == , <= , != etc operators. Read more here: http://bwicki.byond.com/ByondBwicki.dmb?TrueFalse.

You still need to change to that.

The put_out verb should work, just get rid of the pointless argument...you don't need it, since you're using src (with set src).

The warning you get is either for the above argument or for this line: (or both) (next time say which error/warning you get for each line..obviously the line number in your file doesn't help us)
var/obj/fire/F = new(loc)


Because you never do anything with the F var afterwards in that proc, it's an unused (therefore useless) variable. So just change the line to create the object, but not store it into a variable. Mind you, if you remember, the full version (the one you used is a shortcut) of the above line is:
var/obj/fire/F = new /obj/fire(loc)

Therefore, to modify the line to create the object but not store it into a var, we just remove the var assignment:
new /obj/fire(loc)


After doing the above fixes, re-post your code (and problems, if any) and we will see if there's anything left (I'm missing sleep currently so lets take this a little slow :d). Also describe what you want to do here, because it's pretty weird that you have similar 2 different verbs with the same name, that if I gather correctly are gonna end up available at the same time, and you're kinda trying to delete a fire in both.


1) Is there an irc chat for Byond?
I dunno, but there are obviously lots of chatroom games. Use wiz_chat or similar for your programming assistance needs. >.>

2) How do I get a avatar to go next to my forum name? ( i cam't find an option in "preferences".)

I think its for BYOND Members only.
In response to Kaioken
the error was due to the "new" line, and the line you gave to replace it did indeed fix the warning.

i tried the boolean checks when you first recommended them and i had trouble understanding them. However i will look at them again tomorrow, and will post whatever i mangle with my attempts at understanding.

Thank you again for your invalueable advice and assistance.

EDIT::

Oops! that's what i get for coding while i'm cooking. No, the verb "put_out" should not have been under the fire obj! now that i've removed that, my fireplace is safe from usr deletion (for the time being, i think...)

boolean from what i can see is just making the program check to see if the "if" is true or false right? wouldn't that sorta make having the "else"s pointless?

and is it possible in the line "set src in view(1)" to replace src with the fire obj?

lol maybe it would just be simpler to make two seperate icon_states for the fireplace like i did for my windows?