Character change room function

Started by rancidrat, Fri 14/12/2007 15:52:11

Previous topic - Next topic

rancidrat

hi there
Im trying to make a function that I can call from a room script to spawn a npc character.
In a script module i have something that looks like this:


int spawnnpc(int npc, int  view, int xpos, int ypos )
{

character[npc].changeview(view);
character[npc].changeroom(player.room, xpos, ypos);
}

Then:

I call this function in the "before fade in" section
It works fine up till the changeroom command; it seems to get stuck there.
Are you not allowed to use that command in a function? It works when I call the changeroom function seperately, which defeats the object of having a spawnnpc function.

riseryn

I have done the same thing in a game.
It works fine.
But I dont put the changeroom in a function and my character is stored in a room above 300 before I call it (not sure it's really important).
Hope that helps.
:)

Khris

I've tested this and it worked fine for me.
How does the game get stuck? Does it fade in the room at all?
Please copy the exact code you're using and state the version of AGS.

Scorpiorus

Yeah copy-and-past the code from your game.

In case it's a black screen freeze up, then such behaviour is most common for trying to change player character's room to the current (same) one in the "before fade-in" event -- then you may effectively get an infinite loop:

room changes, before fade-in runs, room changes, before fade-in runs, room changes, etc...

Radiant

Are you by any chance using this function to "spawn" the player character?

rancidrat

Um, yeah i'll have to get the code i wrote, its not on this pc
Im not trying to spawn the player character, I do however have a lot more variabes in the function than in the example I got on top. Infact its a struct array thing in a script module
so its kinda like this

int spawnnpc(int npc, int view, int health, string name,int xpos, int ypos)
{
npc[npc].health = health;
npc[npc].name = name;

charachter[npc].changeview(view);
character[npc].changeroom(player.room, xpos,ypos)
}

but there is a lot mor variables, ill have to paste the code I guess cuz its got a lot more variables...
What happens is that the game seems to get stuck before the fade in, as if it was paused with no error message. it works fine when I take out the changeroom bit

also:
even the npc.name string ends up messed up and not what I define in the function.
I did not export the struct, only the spawnnpc function. It still compiles though


Scorpiorus

#6
Yep, we need to look at the exact codes you use.

So...

npc's struct definition (and where did you put it?),
spawnnpc,
and "before fade-in" codes

...would be of primary interest.


EDIT:

And also, where is an npc array is placed (script code / script header) ?
ie: NpcStruct npc[100]; or whatever it's called.

SMF spam blocked by CleanTalk