FirstLoad function being ignored?

Started by Bavolis, Wed 09/05/2012 04:49:13

Previous topic - Next topic

Bavolis

I apologize once again for my foggy logic processors, but I seem to be misunderstanding how this function works. Basically, I want a nonplayer character to show up in a room and play his basic animation. Currently, the entire script for the room itself looks like this:

// GUMBOX room script file
function room_FirstLoad()
{
character[9].SetIdleView(17, 2);
}

Currently, it doesn't work - he just sits there frozen on one frame. However, if I go into the room loading script for the very first room in the game and cut and paste the exact same line, he'll be animating when I enter the room. Likewise, if I paste it into the room before this one as it changes rooms with player.ChangeRoom, that works too. I've even tried changing the above script to:

// GUMBOX room script file
function room_FirstLoad()
{
character[9].ChangeView(17);
}

..and that doesn't work either.

I should point out too that his basic "normal" view is supposed to have animation and it doesn't work either, he just stays frozen. I've been setting idle view for other animating machines and whatnot in the background and it's been working so far. If I take out the set idle views, they don't animate at all when they just sit there (which I think is how it's supposed to be working, right?)

I may be doing it wrong, but the strange thing is I used the exact same method in the previous room with a different character and it works just fine. As far as I can tell, all the settings are identical. I can get it working using the methods I posted above, but it feels like my code is sloppy that way.

One thing that seems to work fine is to set all the idle views in the GlobalScript at game start. Is there any reason not to do it there? And now that gets me all paranoid and I'm wondering if setting up all these little animating background things as characters was the way to go. They have too many animations/different speeds to be part of a 5-frame animating background and each one works with all the interactions.

Gilbert

Have you linked the function to the correct event of the room in the editor? You cannot just create a function by a specific name in the script and hope that it will work automatically (most of the time, as certain functions indeed work automatically).

deadlockuk

Try out
9.Animate(0, 5, eOnce, eBlock, eForwards); function, adjust the View ID and Loop ID respectively.

also choose if you want to animate eOnce or eRepeat.

Khris

deadlockuk: Not only will this not work (you can't name a character "9"), it doesn't address the actual problem.

Bavolis: To reliably test whether a function is called, always use a Display("test"); command, not arbitrary ChangeViews. That way you can be 99,99% sure that the function is actually (not) called.

Bavolis

Quote from: Iceboty V7000a on Wed 09/05/2012 06:05:19
Have you linked the function to the correct event of the room in the editor? You cannot just create a function by a specific name in the script and hope that it will work automatically (most of the time, as certain functions indeed work automatically).

Ahhh, that did it, thanks! I didn't realize you couldn't cut and paste from one room to the next with that function, but deleting it and re-inserting it through the editor tools solved it. Thanks for the assist.

monkey0506

To be clear, the room events (also Character events, InventoryItem events, Object events, Hotspot events, etc.) can be named anything you'd like, you just have to set the proper function name in the relevant Events pane (lightning bolt icon in the properties pane).

Copying and pasting is fine, but until the function is listed in the Events pane it won't be automatically called as appropriate. ;)

Ryan Timothy B

Which I honestly believe should be changed. Where you manually type in a Room_Load function the editor would ask you "Would you like to link this function to the room event Room_Load?"
I hate having to load the room editor just to add a function. You don't need to do it to add an event, repeatedly execute, or repeatedly execute always, etc, functions into a global script, why have it backwards with a room script (not that there is an editor for the global scripts, just saying)?

monkey0506

#7
You don't have to do it for on_event, repeatedly_execute (outside of room scripts which are different), repeatedly_execute_always (including room scripts), on_mouse_click, on_key_press, etc., the "predefined global script functions". The names of these functions cannot be changed (except rep_ex in rooms).

You do have to link functions for Character events, Hotspot events, InventoryItem events, Object events, GUI events, GUIControl events, etc.

Rooms aren't "backwards", they work the same as everything else. (Edit: Actually, I would argue against room_RepExec because it's a regression against every other script that allows a rep_ex function (meaning every other script except dialog scripts), but that's a different story.)

A prompt to link if a function is given the same name as the default event name but there is no function linked to that event may not be a horrible idea, but having the ability to name any function (with the right return type and parameter set of course) is extremely useful. Particularly I have found on more than one occasion that linking multiple items to the same event handler makes more sense than having a bunch of event handlers that just call a similar function (such as when using InventoryItems on each other, I usually handle that in one function).

Khris

What I do is open the room editor once at that start and click the before/after fadein and rep_exec event icons so I have all the usually needed functions.
I rarely need to go back to add another and there's no harm in having one or two empty functions in the script either.

The only suggestion I had in this regard is maybe adding the default names (like room_RepExec) to the auto-complete list in room scripts and linking the function automatically if I hit enter to select the auto-complete suggestion. I think a prompt I have to click away is rather annoying than anything else.

Calin Leafshade

I also think that isa bad idea. What if you want to link several events to a single function? The editor should not presume shit like that.. it's just asking for trouble.

Ryan Timothy B

Alright fine, here's a solution that can meet you guys in the middle.

Instead of requiring you to open the room editor just to add a function to the event editor, why not also have it within the room script? The event pane is just sitting there all lonely waiting for someone to add that function into it. Of course it changes how a room is saved, especially having both the room editor and script editor opened, but shouldn't be too hard to work around (from someone who hasn't examined the editor code in the slightest).

SMF spam blocked by CleanTalk