ID:139268
 
Code:
mob/Moderator
verb
GiveTicket(mob/M in world)
set name="Exp ticket"
set category = "GM"
var/T = new /obj/expticket/
if(T)
T.loc=M // makes T.loc undefined definition ? O.o am i blind?


obj
expticket
name = "Exp Ticket"
icon = 'Ticket.dmi'
verb
use()
set name="Use exp ticket"
usr.expticket = 1
usr << "you have used an exp ticket,(WARNING: do NOT relogg, it will cancel your time)"
del(src)
sleep(10)
usr.expticket= 0
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"


Problem description:

if you read the code above, you will see the code about "giving exp tickets", well... the T.loc doesnt work. no idea why
M.contents+=T should be useful to you.

As well, the reason why you are getting an issue is related to your not defining the location it should be going - M is not a turf, it is a mob. Therefore, a better approach would be

T.loc=M.loc
// OR
T.loc=locate(M.x,M.y,M.z)
In response to Nal_rA (#1)
Nal_rA wrote:
M.contents+=T should be useful to you.

That is roundabout way of moving objects. While it is technically correct, it obfuscates what is actually going on: the contents list is meant to REFLECT the state of the game (specifically, which objects are located within another object). It should not be used to alter the state of the game as you are suggesting.

As well, the reason why you are getting an issue is related to your not defining the location it should be going - M is not a turf, it is a mob. Therefore, a better approach would be

This is not the issue. A mob and a turf are both valid locations for a movable, such as an obj.
Your issue is that you defined the variable T, but never told the compiler what type to expect. You need to define the variable to be of an appropriate type, like so:

var/obj/expticket/T = new()


Also: your use() verb won't work. As soon as you delete src, all of src's procedures will stop, including the use() verb. Therefore, anything after that line is completely unreachable. You will need to either call an external procedure, or you will need to not delete the object until after the rest of the verb is done. You can set its location to null in the meantime so that the player can't use the verb again.
In response to Garthor (#3)
Appreciate the criticism, and nice catch. I didn't notice the lack of variable definition.
In response to Garthor (#3)
oh, makes sence... im not really an HC coder, so im steady at these type of codes x3
In response to Nal_rA (#1)
Nal_rA wrote:
M.contents+=T should be useful to you.

As well, the reason why you are getting an issue is related to your not defining the location it should be going - M is not a turf, it is a mob. Therefore, a better approach would be

> T.loc=M.loc
> // OR
> T.loc=locate(M.x,M.y,M.z)
>


rofl, i didnt try, but i see from here that it wont work as i want. basicly it will be located at the location he is on the map, but not in the inventory. anyways, i got it to work:
obj
expticket
name = "Exp Ticket"
icon = 'Ticket.dmi'
verb
use()
set name="Use exp ticket"
if(usr.expticket==0)
usr.expticket = 1
usr << "you have used an exp ticket,(WARNING: do NOT relogg, it will cancel your time)"
set hidden
sleep(18000)
usr.expticket= 0
del(src)
if(usr.expticket == 1)
usr << "cannot use two tickets at the same time"
return
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
mob/Moderator
verb
GiveTicket(mob/M in world)
set name="Exp ticket"
set category = "GM"
var/obj/expticket/T = new()
if(T)
T.loc=M
In response to Tafe (#6)
The second half of my code would have worked, but I had a misconception of the way location works. But, I'm glad you got it to work. ;)