|
Development Forum |
 |
| 
Geek2Nurse
 

|
6/23/2012 | |
I'm having a weirdness with the inventory that I'm hoping someone can give me some insight into.
I have an agent that has no physics, originally. but if picked up and dropped, it acquires physics and falls. Adding the physics is triggered by the drop (via the drop script).
This works great everywhere in the world. I can pick it up and drop it, and it falls obediently to the ground and bounces a little, just like I want it to. But if I drop it into the inventory, it falls through it to the ground behind. At which point, I can pick it up and drop it again, and this time it falls into the inventory.
Any hints on what's causing this?
---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be. |

Moe
  

|
6/23/2012 | |
Forgive me if I sound like Tech Support telling you to restart your computer, but did you make sure that "carryable" was in the ATTR before it is dropped? I doubt this is the case, but we always want to eliminate the obvious. 
Another possibility is that the drop script is preventing the agent from receiving the signal necessary to initiate the "carry me" process. This can happen if you lock the code.
If you did lock the code, it might be taking precedence over the pickup command and not allowing anything to run a pickup command on this agent until it has finished executing the drop script.
It's like missing a delivery because you weren't home. Where missing the delivery is equivalent to not receiving and processing a pickup request, and not being home is equivalent to having your script in lock at the time the request occurred.
I hope this is the case, otherwise we've got more digging to do. If it is the case, the solution is using INST instead of LOCK.
Also, forgive me if I ever come across condescending. I like to try to make all answers to development questions clear for all levels of coding experience, in case other members see the post and learn.  |

Geek2Nurse
 

|
6/23/2012 | |
I like it simple, Moe; I've only been doing this for a couple of months, so I'd much rather have you sound condescending than give me answers that are over my head. 
The object in question is a flower...I'm not entirely sure WHY one would want to put it into inventory; it's just one of those "being thorough" things, and it bugs me that I can't figure it out! 
The flower is created with attr 39, carryable, mouseable, clickable, floatable -- because initially it floats above its plant. Then at some point it dies and falls off, or else is plucked by the hand or a creature, so then it needs physics.
The pickup script for the flower stops its timer, sends the appropriate stim, and sets an OV on the plant that tells it it no longer has a blossom and needs to start making a new one.
The drop script isn't locked, because I've never figured out the difference between LOCK and INST, so I just use INST. That said, it doesn't use INST either, but it does jump to a portion of the flower timer script that's in an INST, FWIW.
Here's the drop script:
***** Flower Drop Script *****
scrp 2 7 13408 5
* unhook from plant
setv ov01 11
doif from eq pntr
call 9 1 0
else
* send drop stim
stim writ from 19 1
call 9 0 0
endi
* restart timer
setv va90 game "toxes_flwrtick"
setv va91 va90
mulv va91 3
tick rand va90 va91
endm |
Rather than duplicate commands, I just have it call the portion of the timer script that makes flowers fall, by setting it to the age (ov01) at which that happens. If it's falling from the hand, I don't want it to jump around, so I pass a parameter in _p1_ that tells the timer script not to give it any angular velocity. Then I restart the timer so it will go on aging/decaying.
The pertinent timer script code is:
* fall
elif ov01 eq 11
inst
addv ov01 1
* make sure it can move to where it is before giving it gravity
setv va30 posl
setv va31 post
doif tmvt va30 va31 eq 0
kill targ
endi
* (1) carryable (2) mouseable (64) collisions (128) physics
attr 195
* (16) eat (32) pick up
bhvr 48
perm rand 40 80
elas 40
aero 10
fric 30
accg 1.5
* if dropped by the hand, fall straight down
doif _p1_ eq 1
velo 0 0
else
velo rand -3 3 -1
endi
* tell the plant it has no flower
doif ov17 ne NULL
targ ov17
seta ov18 NULL
endi
* slow down to leaf speed
tick game "toxes_leaftick"
slow
* decay (change to detritus)
elif ov01 eq 13
[...] |
EDIT: To clarify, this problem only occurs if the flower is plucked from a plant and placed into inventory -- in other words, when it is acquiring physics for the first time. Once it's fallen to the ground, it's fine.
EDIT2: Thanks to Papriko for pointing out that I should apply the new attr/perm values *before* testing the coordinates with TMVT. So much learning happening here! 
---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be. |

Moe
  

|
6/23/2012 | |
I don't think floating objects can be put in vehicles. Have you considered making the attributes change when the flower is picked up instead of dropped? |

Geek2Nurse
 

|
6/23/2012 | |
Yeah, I have...but that would only solve the problem, not teach me anything.
It seems to me that if the object was still floating, it wouldn't fall into the inventory. Since it does fall from the hand, the drop script obviously has taken effect, so by the time the object gets to the inventory, it isn't a floating object any more. So it should land IN the inventory.
Shouldn't it?
---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be. |

Moe
  

|
6/23/2012 | |
Not necessarily, because inventories that are marked as "greedy" try to grab objects as soon as they are dropped on top of them. The drop script is called after an object has been dropped. It's a split second difference in timing. Even under INST, the drop script just isn't called in time, apparently. |
|