[Newton] Levelchange / .cls problem

Posted By: Daedelus

[Newton] Levelchange / .cls problem - 05/19/05 23:25

Hello,

The Newton physics work great in my first level.
However, the problem is when I build other levels then load them,
the physics entities fall through the floor because
the .cls won't build- only for the 1st level.
It was hard to find an answer on the newton forum.


This is what I have:
=================================
Main script: for level 1 (works)
=================================


ifdef USE_NEWTON_GAME_DYNAMICS;
string newtonLevel_cls = <intro.CLS>;
endif;

string level_str = <intro.WMB>; // Intro level

// now load the level
level_load(level_str);

// initialize newton physics
ifdef USE_NEWTON_GAME_DYNAMICS;
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str);
endif;


=================================
My Levelchange script:
=================================

ifdef USE_NEWTON_GAME_DYNAMICS;
string newtonLevel_cls = <21level0.CLS>;
endif;

ifdef USE_NEWTON_GAME_DYNAMICS;
string newtonLevel_cls = <21level1.CLS>;
endif;

/////////////////////////////////////////////////////
string 21level0_wmb = <21level0.wmb>;

action change_21level0
{
cross_pan.visible = OFF;
while (player == null) {wait (1);}
while (vec_dist (my.x, player.x) > 100) {wait (1);}

level_load(21level0_wmb);
ifdef USE_NEWTON_GAME_DYNAMICS;
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str);
endif;
}


string 21level1_wmb = <21level1.wmb>;

action change_21level1
{
while (player == null) {wait (1);}
while (vec_dist (my.x, player.x) > 100) {wait (1);}
level_load(21level1_wmb);
ifdef USE_NEWTON_GAME_DYNAMICS;
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str);
endif;
}
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/03/05 23:09

Should I bump this or throw the mold out?
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/14/05 22:12

Hi Daedelus,
I´ve seen in the Newton forum that you have a lot of trouble with this problem...

I´ve found this in the newton.wdl:

// NewtonRemoveMap:
// description: destroy the level map
// parameters:
// return:
// remarks: detsroy the map
dllfunction NewtonRemoveMap();

Maybe you must destroy your old map before you can load a new one?
Just an Idea.

greets, fogman
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/14/05 23:33

Quote:

// NewtonRemoveMap:
// description: destroy the level map
// parameters:
// return:
// remarks: detsroy the map
dllfunction NewtonRemoveMap();




Thanks for the suggestion Fogman.
I came across that too but for some reason, my script was causing a "Windows MFC error" and Gamestudio would quit so I put Newton on hold for a while.
I'll probably just start over since its likely a mistake I made somewhere in the process.
Posted By: muralist

Re: [Newton] Levelchange / .cls problem - 06/15/05 16:32

Destroy the level map and also (I think) entities.
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/16/05 17:49

// NewtonRemoveAllBodies:
// description: destroy all physics entities, including the map (usefull for changing levels)
dllfunction NewtonRemoveAllBodies ();

Another one, I think exactly the one you´ll need!
I´m at translating the descriptions in the newton.wdl to german, so I´ll
know all Newton functions in the next days
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/20/05 00:23

I thought I'd make another attempt at this levelchanger script.
While I no longer get that MFC error, I still can't get the .cls file to be created for 21level1.wmb.
The physics work but still fall through the floor because of the .cls not being present.

Here's what I have so far:

//////////////////////////////////////////////////////
ifdef USE_NEWTON_GAME_DYNAMICS;
string newtonLevel0_cls = <21level0.CLS>;
endif;

ifdef USE_NEWTON_GAME_DYNAMICS;
string newtonLevel1_cls = <21level1.CLS>;
endif;


/////////////////////////////////////////////////////
string 21level0_wmb = <21level0.wmb>;

action change_21level0
{
cross_pan.visible = OFF;
while (player == null) {wait (1);}
while (vec_dist (my.x, player.x) > 100) {wait (1);}
NewtonRemoveAllBodies ();
NewtonRemoveMap();
level_load(21level0_wmb);
wait(3);
ifdef USE_NEWTON_GAME_DYNAMICS;
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (newtonLevel0_cls);
endif;

}


string 21level1_wmb = <21level1.wmb>;

action change_21level1
{
while (player == null) {wait (1);}
while (vec_dist (my.x, player.x) > 100) {wait (1);}
NewtonRemoveAllBodies ();
NewtonRemoveMap();
level_load(21level1_wmb);
wait(3);
ifdef USE_NEWTON_GAME_DYNAMICS;
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (newtonLevel1_cls);
endif;

}

Any other ideas?
Posted By: Josh_Arldt

Re: [Newton] Levelchange / .cls problem - 06/20/05 00:50

Here is a siple script that you can use to create the .cls files for your levels.
It should create the .CLS everytime.
Just make sure you save your level before running.

Remember, you must create your 21level1_wmb's .cls file before trying to run and load it through your script.



////////////////////////////////////////////////////////////////////////////
// The engine starts in the resolution given by the follwing vars.
var video_mode = 7; //800x600;
var video_depth = 16; // start in 16 bit resolution

ifdef develop;
plugindir="\\a6\\acknex_plugins";
dllfunction debugmsg(message);
endif;

string s_level=<yourLevel.wmb>;
string s_levelcls=<yourLevel.cls>;

string newtonLevel_cls=s_levelcls;

function main()
{
wait(3);
level_load(s_level);
wait(1);

dll_handle=newtonHandle;
NewtonAddMap(s_level,0);
}
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/20/05 01:40

Thanks for the reply Josh. Im testing out your method now.
My first level actuall is intro.wmb and the .cls always would build fine with the map in the compiler.
Its just the levels after it that don't. 21level0.wmb, 21level1.wmb
Is there anything in the script I posted above that doesen't look right as far as following the Newton instructions?
Posted By: Josh_Arldt

Re: [Newton] Levelchange / .cls problem - 06/20/05 01:46

Quote:

Is there anything in the script I posted above that doesen't look right as far as following the Newton instructions?




The way you did it doesn't seem to build or load the .cls file with A6.31.4.
I'm going to make test levels and see what your script does after I change some things.

It seems we need to somehow change this string "string newtonLevel_cls=s_levelcls;" when the level changes.
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/20/05 07:45

DS Kihaku has mentioned the following:

wait(3);
level_load(s_level);
wait(1);

The wait(3) BEFORE the level_load solve his problems.
If I have time today I´ll play around a little, too.
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/20/05 07:56

Quote:

The wait(3) BEFORE the level_load solve his problems



I have tried that also. Didn't work for me.
My main level works just fine. Its just the others that I change to.
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/20/05 08:50

I´ve played a little, this one works for me.

==================================================

string level_str = <testlevel.wmb>;
string level_str_2 = <testlevel_2.wmb>;
string newtonLevel_cls = <testlevel.cls>;
string newtonLevel_cls_2 = <testlevel_2.cls>;

function main()
{
freeze_mode = 1;
warn_level = 2;
wait(3);
level_load(level_str);
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str, splashscreen);
wait(3);
freeze_mode = 0;
mouse_mode = 1;
mouse_pointer = 1;
mouse_range = 1000;
while(1)
{
mouse_pos.x = POINTER.x;
mouse_pos.y = POINTER.y;
wait(1);
}
}

function levelchange
{
freeze_mode = 1;
warn_level = 2;
wait(3);
level_load(level_str_2);
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str_2, splashscreen);
wait(3);
freeze_mode = 0;
}

on_space = levelchange;

======================================================

I hope this is a part of what you need.

greets, fogman
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/20/05 20:21

Thanks fogman,
Your method definitely works for an on_key method.
Whats strange though is if I assign a player impact action to an invisible entity calling your function, the objects fall through the floor in the next level.

Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/20/05 20:51



Sorry, it´s to late for me now, but be sure, tomorrow I´ll take a look.
I want to learn as much as possible about the 3dgs Newton version,
so it´s helpful for me, too
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/21/05 15:28

Now I´ve the same problems. It falls
trough the floor after level load.

I play a little with it.

[edit]

Duuhh, it´s a bit "spagetthicode", but it works.

The theory: Events calling functions in another kind as key-assigns...
Look at the manual at events.
When I was reading that, another way to call the function came into my mind...

I´ve an action on an entity, by an impact it calls a function.
This function set a variable to 1.

Another function, it´s called by main(), contains a while loop.
It´s checking if the variable is set to one.

--> while(variable == 0){wait(1);)

After that comes the new level load.

So you must call the level load indirectly, not with an event....

I hope you understand that all
Posted By: fogman

Re: [Newton] Levelchange / .cls problem - 06/22/05 09:36

Hi Daedelus, you dont understand my germlish, so I try to explain it
with code...

//===============================================
string level_str = <testlevel.wmb>;
string level_str_2 = <testlevel_2.wmb>;
string newtonLevel_cls = <testlevel.cls>;
string newtonLevel_cls_2 = <testlevel_2.cls>;

var impact_active = 0; // you´ll need this variable to check the event - call

// Here´s my main():

function main()
{
freeze_mode = 1;
warn_level = 2;
wait(3);
level_load(level_str);
wait(1);
dll_handle = newtonHandle;
NewtonAddMap (level_str, splashscreen);
wait(3);
freeze_mode = 0;
mouse_mode = 1;
mouse_pointer = 1;
mouse_range = 1000;
levelchange(); // The levelchange must be called in main()
while(1)
{
mouse_pos.x = POINTER.x;
mouse_pos.y = POINTER.y;
wait(1);
}
}
//=========================

//Here is the action of my levelchange entity:

action impact_test
{
while(player == null){wait(1);}
my.enable_impact = on;
my.event = impact_event;
}

//=========================

//On impact, this event is called:

function impact_event
{
if(impact_active == 1){return;} // is the value of the variable "one" ? Then return.
impact_active = 1; // if not, then now the value is "one".
}
//============================

//The levelchange function checks the value
//of the variable:

function levelchange
{
while(impact_active == 0){wait(1);} // Here it´s checking, after that begins the level load
sleep(3);
freeze_mode = 1;
warn_level = 2;
wait(5);
level_load(level_str_2);
wait(3);
dll_handle = newtonHandle;
NewtonAddMap (level_str_2, splashscreen);
wait(5);
freeze_mode = 0;
mouse_mode = 1;
mouse_pointer = 1;
mouse_range = 1000;
}
//===================================

So you don´t call the function directly with the event.

You use a variable as "switch" to turn the levelchange
function "on".

You´ve to call your levelchange function at gamestart
and it´ll wait until the variable is set to 1.

greets, fogman
Posted By: Daedelus

Re: [Newton] Levelchange / .cls problem - 06/22/05 20:31

Thanks Fogman,
Sent ya a pm.
Can't wait to test this out when I get home
© 2024 lite-C Forums