Switching levels/maps

Posted By: Darrel

Switching levels/maps - 05/26/11 17:18

So, here is my non-working attempt at it. I would appreciate it if someone could show me how it's supposed to be done. I was attempting to make this switch levels on mouse click.


#include <acknex.h>
#include <default.c>


function main()
{
screen_size.x = 800;
screen_size.y = 600;
screen_color.blue = 150;
mouse_mode = 4;
}

function begin_level()
{
while (key_any) {wait (1);}
level_load("ID.wmb");
}


PANEL* main_pan =
{
bmap = "Background.png";
pos_x = 0;
pos_y = 0;

button (518, 520, "Singleplayer2.png", "Singleplayer.png", "Singleplayer2.png", begin_level, NULL, NULL);
flags = OVERLAY | SHOW;
}
Posted By: DJBMASTER

Re: Switching levels/maps - 05/26/11 17:26

Try taking 'while (key_any) {wait (1);}' out of your 'begin_level()' function.
Posted By: Darrel

Re: Switching levels/maps - 05/26/11 18:00

It's still the same result. The script loads but the button doesn't work.
Posted By: Superku

Re: Switching levels/maps - 05/26/11 18:15

I think
"Singleplayer2.png"
is an invalid parameter, you need to use a predefined BMAP pointer.
Posted By: DJBMASTER

Re: Switching levels/maps - 05/26/11 18:29

I just tried your code and it works so I don't see what the problem is. Are you getting some kind of error message?
Posted By: Darrel

Re: Switching levels/maps - 05/26/11 18:47

Nope, no error messages are showing. It starts as a menu page and is supposed to switch to a wmb level on click. Maybe it has something to do with the level I'm trying to load into it. But the level on its own loads as well.

Scratch that, I just tested it and before I clicked the button, my fps was at about 290, after it was like 57. So I think the level is loading, but it's still displaying my background.png.
Posted By: WretchedSid

Re: Switching levels/maps - 05/26/11 19:34

Originally Posted By: Darrel
So I think the level is loading, but it's still displaying my background.png.

Ever thought of making it invisible?
Posted By: Darrel

Re: Switching levels/maps - 05/27/11 06:04

Of course I thought of it, but I don't have the slightest clue as to how to do that. I'm new to Lite-C.
Posted By: DJBMASTER

Re: Switching levels/maps - 05/27/11 12:24

Place 'reset(main_pan,SHOW);' in your 'begin_level()' function. set/reset and toggle are macros (a set of little instructions) that can be used to change the flags of an object at runtime.
Posted By: Darrel

Re: Switching levels/maps - 05/27/11 13:22

function begin_level()
{
level_load("ID.wmb");
reset(main_pan, SHOW);
}

That's what I got, but the script is giving me an error. "'main_pan' is an undeclared identifier."
Posted By: JakeBilbe

Re: Switching levels/maps - 05/27/11 19:21

Shouldnt function_main be at the very bottom?
Posted By: DJBMASTER

Re: Switching levels/maps - 05/27/11 22:54

Lite-C looks for things in order they appear in the script, so it's looking for the PANEL* but it's defined later down in the script.

You can use a 'prototype' which makes the engine aware of a function or object but doesn't have to define it. It can be defined later on...
Code:
#include <acknex.h>
#include <default.c>

function begin_level(); // prototype

function main()
{
screen_size.x = 800;
screen_size.y = 600;
screen_color.blue = 150;
mouse_mode = 4;
}

PANEL* main_pan =
{
bmap = "Background.png";
pos_x = 0; 
pos_y = 0; 

button (518, 520, "Singleplayer2.png", "Singleplayer.png", "Singleplayer2.png", begin_level, NULL, NULL);
flags = OVERLAY | SHOW;
}

function begin_level()
{
level_load("ID.wmb");
reset(main_pan,SHOW);
}


Posted By: Darrel

Re: Switching levels/maps - 05/28/11 05:44

Thanks, but down with one issue and another arises :<
So now the level loaded, but I don't have control over anything like I do when I run the level separately. I don't think it loaded the script for the level.
Posted By: the_clown

Re: Switching levels/maps - 05/28/11 09:04

It can't, because level_load basicly is just a file loading instruction. So it does only load the .wmb file, including all the entities and informations like action names and stuff, but not the script you applied to the level in WED. There's nothing like "changing scripts". You have to have ONE script, or set of sripts, that deal(s) with all levels.
Posted By: Darrel

Re: Switching levels/maps - 05/28/11 15:32

I kinda assumed that last night. Thank you all for the help.
© 2024 lite-C Forums