Game Development Community

Cant Use Triggers

by DevinJ88AZ · in Torque Game Engine · 04/30/2012 (7:50 am) · 7 replies

Hello,

I can't get a trigger to show up from the World Editor Creator (WEC) menu for the life of me! Actually, i've been following a tutorial, with only some name changes, so in theory it should have worked. Whenever I go through the WEC menu and select the defaultTrigger as the data block, it wont show anywhere in the world.

Another issue with this I have is when I create my own data block trigger. Along with the other files, I tell the game.cs file to execute my new trigger file located in the server folder. However, when I boot up Torque, it doesn't compile one of those cs.dso files.

By the way I am using the 1.4.2 version. I've come back to the engine to give it another try. I don't have interest in upgrading. Trust me, I've spent a long long time trying to fix this seemingly simple problem.

Here's the code for my newly made trigger.cs file:

datablock TriggerData(triggerEvent)
{
    tickPeriodMS = 100;
};

function triggerEvent::onEnterTrigger(%this, %trigger,%obj)
{
    echo ("Trigger activated.");
    Parent::onEnterTrigger(%this, %trigger,%obj);
}

function triggerEvent::onLeaveTrigger(%this, %trigger, %obj)
{
    echo ("Trigger exited.");
    Parent::onLeaveTrigger(%this,%trigger,%obj);
}

function triggerEvent::onTickTrigger(%this, %trigger)
{

    echo("Idle.");
    Parent::onTickTrigger(%this, %trigger);
}

#1
04/30/2012 (9:49 am)
I no longer have the older engines installed, but I don't recall any visibility issues with the triggers out of the box... going from memory you could try looking in the "World" menu, I think, and verifying the "Drop at..." position for newly created objects. Make sure that it's not trying to drop them at the Origin, which may be miles away from your position. "Drop at Camera", or "Drop at Screen Center" should be the default.
Quote:
I tell the game.cs file to execute my new trigger file located in the server folder. However, when I boot up Torque, it doesn't compile one of those cs.dso files.
Then you likely have a syntax error within your trigger file or a misnamed file to look for in your exec statement in the game.cs.

Check the console for error remarks -- they will appear in red. If you misnamed the file to exec there will simply be a message about a missing file.
#2
04/30/2012 (10:10 am)
I have the file "trigger.cs" saved in my server folder. Under the game.cs file I put the exec function:

function onServerCreated()
{
   // This function is called when a server is constructed.

   // Master server information for multiplayer games
   $Server::GameType = "Torque TTB";
   $Server::MissionType = "None";

   // Load up all datablocks, objects etc.
   exec("./camera.cs");
   exec("./editor.cs");
   exec("./player.cs");
   exec("./logoitem.cs");
   exec("./trigger.cs");

}

So the file name is right. As for the syntax of my trigger.cs file? The code is above in my original post.

I did as you said with the "drop at.." options. Nothing works there. However, looking up above at my code, shouldn't I have the option to select my trigger "triggerEvent" ? I don't even have the option to select this trigger under the data block drop down list. The only trigger that is available is the defaultTrigger that comes with Torque. Again, even if I select it and try to put it into my mission, nothing shows up at all.
#3
04/30/2012 (10:42 am)
Delete the old game.cs.dso script file, if there is one, to make sure that the engine knows that a newer version of the file exists. Then if it compiles and the trigger.cs doesn't you will know that the error lies within the trigger.cs file.


$Server::GameType = "Torque TTB";
TTB. That is the old Torque Tutorial Base isn't it? If I remember correctly, that doesn't have a default trigger defined anywhere in the scripts. I bet that if you look in the console you'll see an error message about object defaultTrigger not being a member of GamebaseData, and register object failed for class Trigger whenever you try to create it. But you shouldn't actually need it if you can select some other working trigger datablock, even though it will still show up in the list and fail to create until you do define one.
#4
04/30/2012 (11:15 am)
Hey thanks for the replies,

I suppose it is an older version. I did a fresh install. I couldn't find any definition for the trigger either, so I was surprised to find it as an option for a trigger. Not surprising, trying to use it didn't yield any results.

I deleted the game.cs.dso file and restarted the engine, the trigger still did not compile. You were right about the error message being displayed in the console.

Now I am still stuck at getting my own custom trigger to show up as a selectable datablock. I guess that means there is a syntax error, but I copied the code from a tutorial and nothing seems to work. I am all out of ideas how to remedy this.
#5
04/30/2012 (11:29 am)
I don't see any obvious syntax errors in that code, or in the exec statement. What are you using as a script editor? I ask because some text editors may leave hidden formatting that can cause unexplainable errors such as this.

If you want, you can send your console.log, game.cs, and trigger.cs to my email -- it's listed under my profile.
#6
04/30/2012 (11:55 am)
Oh jeez, Thanks!

I was using MS Visual Studio 2010 Ultimate. I simply deleted my trigger file then created an empty text document. Pasted the code right into the document and saved the file name as "trigger.cs".

After I loaded the engine I could select my trigger and the code executed as it should. Thanks a lot for the replies!

Any suggestions for editors?
#7
04/30/2012 (1:09 pm)
I wouldn't think that VS would leave a formatting artifact, but at least it's working now!

Technically any text editor will work for Torque Script. Visual Studio is more than sufficient, and something as simple as Notepad will work. Most people around here tend to favor Torsion since it has Torque Script highlighting and error checking. I'm using a custom modified version of a freeware open source editor called Crimson Editor -- it's really just a matter of personal preference. But do stay away from anything labelled as a word processor.

Oh, meant to mention this earlier, but you can copy the DefaultTrigger datablock and code from the trigger.cs in either the Demo or the fps.starter scripts, if you want to enable the Editor's DefaultTrigger.