PDA

View Full Version : Stuck:/ get RoomID of scripted object


Consort
17th May 2012, 07:55 PM
I'm stuck with this really stoopit little problem:

I cloned a sign-object and successfully wired up my override code from some painting. My code fires properly, my interactions work etc.

Problem: The Object does not know it's own RoomID.

I'm doing this on startup. The code fires when I buy/place the object:

public override void OnStartup()
{
base.OnStartup();
NotifyDebug("This.roomid" + this.RoomId + " lotid " + this.LotCurrent.LotId);


}

roomID is always 0, LotID gives a valid looking value.

Why is roomID giving me a wrong value?
My house is ok, sim->object interactions show the correct roomID

Buzzler
17th May 2012, 09:00 PM
First, your object is *not* outside, right? Just checking.

I'd suggest to delay the notification for a moment. Might just be a timing issue if later calls through interactions show a non-zero room id.

Consort
17th May 2012, 09:11 PM
Ooh I just found out what the matter is...

OnStartup() fires when you grab the object in buy mode, not when you place it. Thats why I'm getting the correct LotID but no proper RoomID.

Now wondering where to put that code instead...

Consort
19th May 2012, 12:55 AM
Well. The issue is still not resolved (at least I'm not stuck anymore)

I also tried OnCreation() but it fires simultaneously.
OnLoad() hopefully fires on load (still have to test that)
Funfact: It seems both fire twice the first time I grab the object in the build menu.
This kinda doesnt make sense to me.

edit:
Epic. OnLoad() gets invoked on load but this.roomID is still -1 at that point. :cry:

Buzzler
19th May 2012, 06:25 PM
You did have a look at the other On$Something() methods, I assume?

Other than that, I'd just suggest to just delay your code. Let the object add an alarm to itself in OnStartup() and set the timer to one second or something.

Consort
19th May 2012, 07:33 PM
GameObject has 52 On$Somethings. I'm not done trying yet ;)
OnHandToolPlacement sounds kinda promising I must admit. Will try that later.

The timed delay won't work for OnCreation/OnStartup since the user could grab the object from the build menu, go for a coffee and then place it. It might work to fix the OnLoad, not sure how reliable that is.

I have solved the issue with persistability (which i'm gonna need anyway). The user has to arm the sign anyway, thats not a bad moment to have it check where it's located. The downside of this solution is that the sign does not refresh when the world is loaded and might target a wrong room if the building has changed.

Buzzler
19th May 2012, 07:37 PM
The timed delay won't work for OnCreation since the user could grab the object from the build menu, go for a coffee and then place it. It might work to fix the OnLoad, not sure how reliable that is.OnLoad() will only be called if you load a game that already has the object in it. OnCreation() will be called when you click on the icon in the catalog and the object gets created.

And the delay will work, because the alarms aren't based on real time, but game time. One second will only pass, if you leave build/buymode and unpause the game.

Consort
19th May 2012, 11:47 PM
Oh of course, now I get it :)

Do you have an explanation why it would fire twice when I click the object in catalog when i'm doing it for the first time?