Game Development Community

Scripting Help

by Derek Wayne Root · in Torque Game Builder · 04/16/2011 (5:26 pm) · 2 replies

In the code below, I don't understand a number of things. I've tried doing all the tutorials, but the scripting keeps messing me up, because I'm just not grasping some of these concepts. Here's one of the questions that's bugging me to no end.

I thought that sceneWindow2D.loadLevel(%level) is the command that causes a level to be loaded into the window, but the program keeps defying that assumption. Here's an example: I created two scenes and named the levels "FirstScene" and "SecondScene" and then I went into the game.cs file and changed it so that %level became %FirstScene. This didn't work and the program loads another file "untitled" and displays a black screen. I'm obviously misunderstanding something here...

Why is the command sceneWindow2D.loadLevel(%level) set to "%level" when there is no scene or level titled "level"? How do I tell this program to load a different level? I tried toying with the loadLevel command, but it doesn't seem to be working.

Also, in the code you see that they have "new ActionMap" listed and I've been researching the heck out of this program and I think that ActionMap allows for images to move across the screen, but what is the "new" command all about? I mean, I've seen it used sometimes and then not used other times. My assumption is that it's just a tag to tell us that the "ActionMap" thing is a 'new' feature, but I could be completely wrong (I probably am).



function startGame(%level)
{
   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);
   
   new ActionMap(moveMap);   
   moveMap.push();
   
   $enableDirectInput = true;
   activateDirectInput();
   enableJoystick();
   
   sceneWindow2D.loadLevel(%level);
}

function endGame()
{
   sceneWindow2D.endLevel();
   moveMap.pop();
   moveMap.delete();
}

About the author

Recent Threads


#1
04/16/2011 (6:20 pm)
@Derek - The %level variable is passed in through the startGame function as a parameter:

function startGame(%level)

That variable contains the level the game will load. sceneWindow2D is an object every Torque 2D project starts with. This is the main window interface, which is why it is responsible for loading a level. If you want to use a different level, you will need to change what gets loaded in. For example, let's say you have a level called myLevel.t2d. You would do this instead:

%someLevelToLoad = "game/data/levels/myLevel.t2d";

sceneWindow2D.loadLevel(%someLevelToLoad);

ActionMap is a class that specifically handles input. All mouse, keyboard and joystick actions are bound to this object. Before you can use the functionality, you need to declare one:

new ActionMap(moveMap);

Then, you need to activate it. This is done using the push method:

moveMap.push();

If you want an overview of TorqueScript, check out the iTorque 2D Documentation. Torque 2D and iTorque 2D are built on the same technology, so the documentation on scripting applies. Be sure to read the Overview and Syntax Guide docs.

If you want a more detailed overview of ActionMap, have a look at the TGB Documentation. It is located under Reference->Input Interaction. Apologies for the formatting. Something messed up when it was uploaded online.
#2
04/16/2011 (6:20 pm)
I am away from my computer but I will try from memory.


scene1.t2d is a level that you would like to load. What I think you are doing wrong is not calling the string of that file (scene1) location so.... What I think you need to do is this...

SceneWindow2D.loadLevel("~data/levels/scene1.t2d");


If you look more closely at the examples you will see a clear example.