1 registered members (Akow),
1,361
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Load level from string1
#248113
01/24/09 16:23
01/24/09 16:23
|
Joined: Nov 2008
Posts: 50
Secret_V
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2008
Posts: 50
|
I'm creating an RPG, so I need a lot of doors and teleports to other levels in my game world. Now, I don't want to use another action/function for every single door, so I want to load the level from the string1, which is manually set in WED. But I can't seem to get this working. This is my code up till now:
action door()
{
set(my, POLYGON);
my.emask |= ENABLE_CLICK;
my.event = door_open;
}
function door_open()
{
var door_percentage;
if((event_type == EVENT_CLICK) && (vec_dist(player, my) <= 100))
{
while(door_percentage < 100)
{
ent_animate(my, "open", door_percentage, 0);
door_percentage += 3 * time_step;
wait(1);
}
level_load(my.string1);
in_building = 1;
}
} I tried different contexts for string1, like: "player_house.wmb" player_house.wmb But it loads an empty level each time. Can anyone tell me what's the matter with my code? Cause I don't feel like using a different action for every door I use.
|
|
|
Re: Load level from string1
[Re: Secret_V]
#248119
01/24/09 17:18
01/24/09 17:18
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
i think the level_load command destroys first the level (and your string1 too) and then loads the level. But at this time your string1 is = NULL so the engine loads an empty level. Try this:
STRING* dummy = "#32";
...
str_cpy(dummy,my.string1); level_load(dummy);
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Load level from string1
[Re: WretchedSid]
#248128
01/24/09 18:04
01/24/09 18:04
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
uhm is you mouse activated + mouse_range?
does it work if you replace my.string1 true the normal name of the lvl "lvl.wmb"
"empty"
|
|
|
Re: Load level from string1
[Re: flits]
#248132
01/24/09 19:00
01/24/09 19:00
|
Joined: Nov 2008
Posts: 50
Secret_V
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2008
Posts: 50
|
Well, I changed things to:
STRING* load_level = "#32";
action door()
{
set(my, POLYGON);
load_level = my.string1;
my.emask |= ENABLE_CLICK;
my.event = door_open;
}
function door_open()
{
var door_percentage;
if((event_type == EVENT_CLICK) && (vec_dist(player, my) <= 100))
{
while(door_percentage < 100)
{
ent_animate(my, "open", door_percentage, 0);
door_percentage += 3 * time_step;
wait(1);
}
in_building = 1;
str_cpy(load_level, my.string1);
if(door_percentage >= 100) level_load(load_level);
}
}
But now I get the error message: Error E1515 Invalid arguments in door_open And then it loads an empty level. My mouse is activated and I've set the mouse_range. Yes, my level loads when I replace my.string1 with the real level name.
|
|
|
Re: Load level from string1
[Re: Secret_V]
#248190
01/25/09 06:53
01/25/09 06:53
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
Serious User
|
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
First of all you should put the level_load command into an own function that starts with to be sure that this function is still running after the level_load commnand has been executed, because you should add at least a after the level_load(); Try something like that (I have not tested this code):
action door()
{
set(my, POLYGON);
my.emask |= ENABLE_CLICK;
my.event = door_open;
}
void load_new_level(STRING* level_name)
{
my = NULL;
level_load(level_name);
wait(1);
}
function door_open()
{
var door_percentage;
if((event_type == EVENT_CLICK) && (vec_dist(player, my) <= 100))
{
while(door_percentage < 100)
{
ent_animate(my, "open", door_percentage, 0);
door_percentage += 3 * time_step;
wait(1);
}
in_building = 1;
if(door_percentage >= 100) load_new_level(str_create(my.string1));
}
}
Regards, Pegamode.
|
|
|
Re: Load level from string1
[Re: Secret_V]
#248253
01/25/09 16:40
01/25/09 16:40
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! Since you changed level you probably have to re-activiate the door with set(my, POLYGON); my.emask |= ENABLE_CLICK; my.event = door_open; place these lines in a function and after loadint the new level call the function. Ottawa
|
|
|
|