February 04, 2012, 03:34:18 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Creating a Day/Night Cycle?  (Read 1305 times)
tofugames
Newbie
*
Posts: 11



View Profile
« on: August 04, 2010, 07:50:51 PM »

     Hi, I am completely new to GC and C-style programming. I know basic python, and some smaller, lesser known languages, but have never programmed in C, or any C-style languages. I am not a beginner programmer, but I would consider myself a complete beginner to C-style programming.

    I have been using GC for about 3 days now, and have made basic terrains, and have pretty much figured out most of how the editor works. I, however, dont yet understand scripting in GC. I went into the scripts tab, and saw main.gsl but nothing else. So, I then tried to create a new script, but it didnt seem like the game read or used it (since no script errors came up). So, then I took my script and put it in the bottom of the main.gsl script. When I did this, I got a bunch of script errors, so I'm not sure why my new script wasn't used by the game..

    The script I tried to use to make a day/night cycle was:
Code:
float myvar1;
myvar1 = 0;
main()
{
myvar1 = myvar1 + 0.1;
SetTimeOfDay( myvar1 time);
sleep(100);
return main();
}

and that didnt work. I honestly have no idea how to make a script for a Day/Night cycle but thought SetTimeOfDay would be the best way to go since I like the SkySystem in GC.
Any help would be great! Thanks!  Smiley
Logged
Jim
Jr. Member
**
Posts: 85



View Profile WWW
« Reply #1 on: August 04, 2010, 11:33:04 PM »

I haven't done any scripting in quite a while, and never used the sky system, but how are you calling this function? and what are you doing with return main()?
Logged

www.gamecreation.ca - gamecore stuff.
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #2 on: August 04, 2010, 11:53:38 PM »

     Well, I just have it in the main.gsl file before the closing bracket to void MainGame()
I'm using return main() to make an infinite loop of the function every 100 milliseconds. Although I'm not sure I'm doing it right because I'm new to this style of programming.. I havent done any other edits to main.gsl yet; Just the default. This is my current main.gsl:

Code:
/*****************************************************************************

main.gsl


Beyond Virtual Main Game Script (GSL)

Every Game needs a high-level main.gsl file which provides
save game & main game loop.

All GSL scripts run from top to bottom in sequential order
The main.gsl file represents your entire game's order of missions.

*****************************************************************************/


// main game execution
void MainGame()
{
GameManager@ game = GetGameManager();
if (game.GetPlayerCount() == 0)
Error( "Error: No player object defined. Make sure the 'Make Player' checkbox is checked for the player object.");

// setup the player
Player@ player = game.GetPlayer( 0);
game.SetPlayerInputRemapping( "Player", player.GetName());

// tell the viewport which player is the local one
Viewport@ viewport = game.GetViewport( "Main");
viewport.SetViewToPlayer( player);

while (true)
{
// this delay is needed to allow the other game processes to run
WaitForRender();
}

// we passed the level
CloseGame();
NewWorld();
SetRelativeMouseMode( false);
ShowForm( "LevelSelectDialog");

        // Day/Night
        float myvar1;
        myvar1 = 0;
        main()
        {
        myvar1 = myvar1 + 0.1;
        SetTimeOfDay( float( myvar1));
        sleep(100);
        return main();
        }
}
Logged
Jim
Jr. Member
**
Posts: 85



View Profile WWW
« Reply #3 on: August 05, 2010, 12:07:22 AM »

I don't think you can return a function, like I said though I haven't done any scripting for about a year now I think, so if I say something stupid please forgive me Wink

What you could do to make the loop is

while(true)
{
  // day / night cycle function stuff
}

But if you you create an infinite loop there your script won't move on to any other part of the game script. I'm not home right now and not too sure how exactly the main scripts work anymore, but shouldn't you put that stuff inside the existing while true loop? It seems like the game is going to be stuck there...


What version of GameCore are you using and which template?
« Last Edit: August 05, 2010, 12:10:43 AM by Jim » Logged

www.gamecreation.ca - gamecore stuff.
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #4 on: August 05, 2010, 12:20:49 AM »

I'm using 2.5 Indie with the Island Demo template. I see what you mean about the infinite loop problem. I'll put it in the existing loop and see what happens.  

Edit: After reading some forum posts and documentation, and moving the Day/Night stuff to the current infinite loop, I've changed my script to this:
Code:
/*****************************************************************************

main.gsl


Beyond Virtual Main Game Script (GSL)

Every Game needs a high-level main.gsl file which provides
save game & main game loop.

All GSL scripts run from top to bottom in sequential order
The main.gsl file represents your entire game's order of missions.

*****************************************************************************/


// main game execution
void MainGame()
{
GameManager@ game = GetGameManager();
if (game.GetPlayerCount() == 0)
Error( "Error: No player object defined. Make sure the 'Make Player' checkbox is checked for the player object.");

// setup the player
Player@ player = game.GetPlayer( 0);
game.SetPlayerInputRemapping( "Player", player.GetName());

// tell the viewport which player is the local one
Viewport@ viewport = game.GetViewport( "Main");
viewport.SetViewToPlayer( player);

while (true)
{
// this delay is needed to allow the other game processes to run
WaitForRender();
        SetTimeOfDay( float( 1.0));
}

// we passed the level
CloseGame();
NewWorld();
SetRelativeMouseMode( false);
ShowForm( "LevelSelectDialog");
}

But I still get a script error and in the console it gives me this:
Quote
media/scripts/main.gsl (18, 1): Compiling void MainGame()
media/scripts/main.gsl (36, 9): No matching signatures to 'SetTimeOfDay(const double)'
Could not find entry function 'void MainGame()' in script '../scripts/main.gsl' -  (error from script menu.gsl, line 51)
« Last Edit: August 05, 2010, 12:30:23 AM by tofugames » Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #5 on: August 05, 2010, 01:46:14 AM »

Code:
media/scripts/main.gsl (36, 9): No matching signatures to 'SetTimeOfDay(const double)'

you can't call "SetTimOfDay" like that, you have to call it with
Code:
GetGameManager().GetWorld().SetTimeOfday( 0.5);
look at the doc, and don't forget to activate the sky system in your world.

Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #6 on: August 05, 2010, 12:56:55 PM »

      Oh, I didn't see that. Thanks LutinMalefique!  Smiley It works now, except it is extremely fast because I have it in the infinite loop, but don't have any kind of sleep function in it. I tried sleep() but that didn't seem to work so I guess that must not be the right command for having the script wait an x number of milliseconds before continuing? I looked through the documentation and couldn't find anything on a sleep() function...  Huh

EDIT: Ahh okay I found it. Delay();

So, I now have a working Day/Night cycle! Cheesy
Code:
/*****************************************************************************

main.gsl


Beyond Virtual Main Game Script (GSL)

Every Game needs a high-level main.gsl file which provides
save game & main game loop.

All GSL scripts run from top to bottom in sequential order
The main.gsl file represents your entire game's order of missions.

*****************************************************************************/


// main game execution
void MainGame()
{
GameManager@ game = GetGameManager();
if (game.GetPlayerCount() == 0)
Error( "Error: No player object defined. Make sure the 'Make Player' checkbox is checked for the player object.");

// setup the player
Player@ player = game.GetPlayer( 0);
game.SetPlayerInputRemapping( "Player", player.GetName());

// tell the viewport which player is the local one
Viewport@ viewport = game.GetViewport( "Main");
viewport.SetViewToPlayer( player);



while (true)
{
    GetGameManager().GetWorld().SetTimeOfDay( GetGameManager().GetWorld().GetTimeOfDay()+0.001);
Delay( 0.1);
WaitForRender();
}
   
// we passed the level
CloseGame();
NewWorld();
SetRelativeMouseMode( false);
ShowForm( "LevelSelectDialog");
}
Thanks for your help Jim and LutinMalefique! Cheesy
« Last Edit: August 05, 2010, 01:03:59 PM by tofugames » Logged
LutinMalefique
Full Member
***
Posts: 146



View Profile WWW
« Reply #7 on: August 05, 2010, 04:00:31 PM »

you're welcome

i was planning to implement a day/night cycle in my Sponza demo, i think i will rework on that in the next days
Logged

http://lutinmalefique.wordpress.com/
"Just remember: a damn game can be played, and if you have not created something that can be played, it's not a damn game!" Derek Yu
Jim
Jr. Member
**
Posts: 85



View Profile WWW
« Reply #8 on: August 06, 2010, 12:24:23 AM »

No problem, I need to brush up on my scripting anyways... LutinMalefique, I might start working on something similar to you, only a space invaders one vs 1942 Smiley I like your curves you implemented.
Logged

www.gamecreation.ca - gamecore stuff.
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #9 on: August 06, 2010, 12:36:57 PM »

     I had one more question that just came up. I am trying to add stars to the night, but it looks like SkySystem wont let me change the sky texture? If, I cant change the sky texture in SkysSystem, is there another way to amke a Day?Night cycle so I can change the sky texture? Thanks, Smiley

~~Tofugames
Logged
ross.rockafellow
Global Moderator
Full Member
*****
Posts: 142



View Profile
« Reply #10 on: August 06, 2010, 02:18:04 PM »

This is just the first Idea I had, but it might work if you make a big dome with the star textures. If you set the alpha up right the daylight should "hide" the stars due to brightness, then when the night cycle begins they become visible (with a slight Luminosity on the surface).

That could be a terrible idea, not sure, its Friday Wink
Logged
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #11 on: August 06, 2010, 06:18:36 PM »

I got a sphere and got it in-game, but then noticed it wasn't hollow, and that Gamecore doesn't take jpg textures. So now I'm trying to make a hollow sphere with a different texture format, but it's not going so well.. I have really ever modeled before so it's a big learning curve trying to get this working..  Undecided

EDIT: Okay, I got a working object, and got it into GC fine, but for some reason in GC the texture is all screwed up, but in Blender and Milkshape it's fine.. And when I get close to one edge of the object in GC the other edge starts to disappear and show the default sky and horizon and etc... Undecided And there is also a really annoying flashing line in between polygons in the object, like the polygons aren't quite connected and I can barley see a sliver of the default sky..

This screen shows all of the problems:
« Last Edit: August 06, 2010, 08:42:05 PM by tofugames » Logged
Jim
Jr. Member
**
Posts: 85



View Profile WWW
« Reply #12 on: August 06, 2010, 10:59:23 PM »

GameCore will accept jpg's as textures, what problem are you having with that?

The disappearing edge is the far clip plane, you could set it higher, or use a different method... Like I said I'm not familiar with the sky system, maybe there is something in the environment panel that can help you?
Logged

www.gamecreation.ca - gamecore stuff.
tofugames
Newbie
*
Posts: 11



View Profile
« Reply #13 on: August 07, 2010, 12:26:36 AM »

Well, when I tried using a .jpg it got a load error and said it wasn't an acceptable format.. But I changed it to a .png and it's all fine now. And okay, I'll take a look at the far clip plane. I've looked through the environment stuff a lot, and haven't fond anything. I can set the sky color for the SkySystem and the horizon color, but no sky textures take effect unless the SkySystem is disabled. I'm still not sure what to do about the little 'lines' that show through the model like on the far right in the picture.. As well as what to do about the weird texture.. but I'll keep looking around.  Thanks! Smiley

EDIT: Okay, I've got everything working except the messed up texture and weird lines showing through sometimes.. I have no Idea how to fix those problems..  Undecided I also don't have the changing alpha in yet, but I decided not to try to figure that out until I fixed the other problems.
« Last Edit: August 08, 2010, 03:14:40 AM by tofugames » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #14 on: August 08, 2010, 05:45:05 PM »

it might be that you are saving in jpg2000 or some sort of non-standard compression. Should work with normal jpg files
Logged
Pages: [1] 2
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!