Pop Up Note
by George Fairs · in Torque Game Builder · 05/04/2010 (9:31 am) · 13 replies
Hey everyone, I am very new to the programming side of TGB and got the PSK a few days ago. I want to make it so when you run through a trigger box, a GUI message pops up with a tutorial note, and a continue button or 'X' so you can close it...
Does anyone know of any tutorials, or be willing to help me create this? If so, thanks a bunch!
P.S (Just another question, can you release a game to be sold with the graphics that come already in the PSK?? Thanks!)
Does anyone know of any tutorials, or be willing to help me create this? If so, thanks a bunch!
P.S (Just another question, can you release a game to be sold with the graphics that come already in the PSK?? Thanks!)
About the author
#2
05/04/2010 (2:39 pm)
Creating dialogs can be easy, or a royal pain in the ass, depending on how you want to handle it. When I get home from work (hopefully within the next hour or so), I'll put something together to help you out, if nobody else has pointed you in the right direction by that point.
#3
About trigger problem, as a skeleton to start with, you could follow these few instructions.
- Add a trigger object (t2dTrigger) to the level
- Set a class for the trigger (i.e. MyTriggerClass)
Inside the .t2d level file, your trigger should look similar to
- At the end of ~|game|gameScripts|game.cs insert a code like this
When an object (i.e. a t2dStaticSprite) enter the trigger, the MessageBoxOKDlg will pop up.
If you are not familiar with TS (Torque Scripting), I suggest to buy Torsion by Sickhead Games.
Last advice. Before trying to do exactly what you want, try to complete all the documentation tutorials: it will be very useful and you will understand all basic TGB elements.
05/04/2010 (2:58 pm)
About PSK you should refer to the license. If you have any doubts, you could look at the official private forum TGB Platformer Kit (Private).About trigger problem, as a skeleton to start with, you could follow these few instructions.
- Add a trigger object (t2dTrigger) to the level
- Set a class for the trigger (i.e. MyTriggerClass)
Inside the .t2d level file, your trigger should look similar to
...
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "MyTriggerClass";
useMouseEvents = "1";
Position = "2.570 7.076";
size = "36.559 29.067";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "3";
};
...- At the end of ~|game|gameScripts|game.cs insert a code like this
...
function MyTriggerClass::onEnter(%this, %object)
{
echo("object" SPC %object SPC "entered the trigger.");
//Set message text
MBOKText.setText("I'm a tutorial");
//Open a predefined gui (you can find MessageBoxOKDlg
//definition inside ~|common|gui|messageBoxOk.gui)
Canvas.pushDialog(MessageBoxOKDlg);
}
...When an object (i.e. a t2dStaticSprite) enter the trigger, the MessageBoxOKDlg will pop up.
If you are not familiar with TS (Torque Scripting), I suggest to buy Torsion by Sickhead Games.
Last advice. Before trying to do exactly what you want, try to complete all the documentation tutorials: it will be very useful and you will understand all basic TGB elements.
#4
I will be sure to try it all out (can't right now), and thanks for the advice throughout... I think I'm always trying to 'run before I can walk'. I will post how it went soon.
Thanks again...
(More replies are welcome :D)
05/04/2010 (11:36 pm)
Thanks very much both Samantha for maybe helping soon, and Giuseppe for this awesome mini tutorial :)I will be sure to try it all out (can't right now), and thanks for the advice throughout... I think I'm always trying to 'run before I can walk'. I will post how it went soon.
Thanks again...
(More replies are welcome :D)
#5
The only problem now is, how can I make the trigger delete itself after OK has been pressed? Thanks in advance!
05/05/2010 (8:24 am)
Awesome, many thanks for the script, it worked :)The only problem now is, how can I make the trigger delete itself after OK has been pressed? Thanks in advance!
#6
and that deleted the player :P
Then I tried adding:
Any ideas?
Thanks
05/07/2010 (8:48 am)
Ermm... I tried doing the self-deleting thing, but it didn't work. First I tried adding this* to function MyTriggerClass::onEnter(%this, %object)
{
echo("object" SPC %object SPC "entered the trigger.");
//Set message text
MBOKText.setText("I'm a tutorial");
//Open a predefined gui (you can find MessageBoxOKDlg
//definition inside ~|common|gui|messageBoxOk.gui)
Canvas.pushDialog(MessageBoxOKDlg);
*%object.delete();
}and that deleted the player :P
Then I tried adding:
%this.delete();which made the game crash.
Any ideas?
Thanks
#7
as you discovered, the %object passed to the onEnter function is the sprite, not the trigger itself.
About %this variable, that is the correct variable pointing to the trigger. Anyway, you are trying to delete an object from inside one of its own methods, so this is why TGB crashes. ^^
I suggest to delete items only if you rellay need to do so, in other cases, simply disable objects. You can use something like this:
before the onEnter method ends.
If you really need to delete the trigger, you can simply defer the delete command. This is a best practice for all objects you need to delete, and you can use something like this:
Please note some TGB objects (like t2dStaticSprite or even t2dTrigger) offer a more elegant and specific safeDelete() method to achieve the same result.
Happy coding.
05/10/2010 (7:34 am)
Hi George,as you discovered, the %object passed to the onEnter function is the sprite, not the trigger itself.
About %this variable, that is the correct variable pointing to the trigger. Anyway, you are trying to delete an object from inside one of its own methods, so this is why TGB crashes. ^^
I suggest to delete items only if you rellay need to do so, in other cases, simply disable objects. You can use something like this:
%this.setEnabled(false);
before the onEnter method ends.
If you really need to delete the trigger, you can simply defer the delete command. This is a best practice for all objects you need to delete, and you can use something like this:
%this.schedule(32, "delete");
Please note some TGB objects (like t2dStaticSprite or even t2dTrigger) offer a more elegant and specific safeDelete() method to achieve the same result.
Happy coding.
#8
Now all I have to do it find a way to organise the messages better, rather than putting them all in game.cs.
To do this would I have to create another file with all the messages in and then call it from game.cs?
Thanks!
EDIT: The first method seemed to be causing a problem with multiple messages, so I switched to the latter method and it still doesn't work. Basically you enter the trigger of message 1, it pops up, you click ok. Then you enter trigger 2 and nothing happens.
Sorry for the inconvenience, but thanks in advance for any help :)
Bye!
05/10/2010 (1:03 pm)
Thanks you so much again Giuseppe, the first one I tried (%this.setEnabled(false);) worked perfectly! Now you can walk back to the same spot and the message doesn't pop up :)Now all I have to do it find a way to organise the messages better, rather than putting them all in game.cs.
To do this would I have to create another file with all the messages in and then call it from game.cs?
Thanks!
EDIT: The first method seemed to be causing a problem with multiple messages, so I switched to the latter method and it still doesn't work. Basically you enter the trigger of message 1, it pops up, you click ok. Then you enter trigger 2 and nothing happens.
Sorry for the inconvenience, but thanks in advance for any help :)
Bye!
#9
if you set two different t2dTriggers, i.e. like this
they will not disable each others, because when you refer to %this inside the onEnter method, you are referring the specific entered t2dTrigger. Your problem should be somewhere else: is the onEnter method entered? Set an echo and check the console.
Please note pushing dialogs with Canvas.pushDialog() method does not push that gui (MessageBoxOKDlg in your case) twice: you must close the current pushed gui BEFORE the next onEnter event occurs, or your gui will not pop up, even though the method is correctly entered.
If you have more troubles, check this working sample I jsut made for you.
Happy scripting,
byez.
--
My weekly advice:
Use Dropbox (online backup, file sync and sharing made easy): it really changes the way you manage your files. Forever. ^^
05/10/2010 (1:44 pm)
Hi George,if you set two different t2dTriggers, i.e. like this
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TriggerClass";
useMouseEvents = "1";
Position = "12.145 6.667";
size = "5.709 6.667";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "4";
};
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TriggerClass";
useMouseEvents = "1";
Position = "21.721 6.779";
size = "6.559 6.441";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "5";
};they will not disable each others, because when you refer to %this inside the onEnter method, you are referring the specific entered t2dTrigger. Your problem should be somewhere else: is the onEnter method entered? Set an echo and check the console.
Please note pushing dialogs with Canvas.pushDialog() method does not push that gui (MessageBoxOKDlg in your case) twice: you must close the current pushed gui BEFORE the next onEnter event occurs, or your gui will not pop up, even though the method is correctly entered.
If you have more troubles, check this working sample I jsut made for you.
Happy scripting,
byez.
--
My weekly advice:
Use Dropbox (online backup, file sync and sharing made easy): it really changes the way you manage your files. Forever. ^^
#10
I am not entirely sure what I should be looking for, so here's my main.cs section for the tutorial messages:
I am sorry if I have just missed something completely obvious.
Thanks in advance...
(And what a neat little example ;D)
05/10/2010 (2:04 pm)
Thanks again for the quick reply.I am not entirely sure what I should be looking for, so here's my main.cs section for the tutorial messages:
function TutorialNote1::onEnter(%this, %object)
{
echo("object" SPC %object SPC "entered the trigger.");
//Set message text
MBOKText.setText("Welcome! This is the tutorial level.");
//Open a predefined gui (you can find MessageBoxOKDlg
//definition inside ~|common|gui|messageBoxOk.gui)
Canvas.pushDialog(MessageBoxOKDlg);
%this.setEnabled(false);
}
function TutorialNote2::onEnter(%this, %object)
{
MBOKText.setText("Down there is a mushroom!");
Canvas.pushDialog(MessageBoxOKDlg);
%this.setEnabled(false);
}I am sorry if I have just missed something completely obvious.
Thanks in advance...
(And what a neat little example ;D)
#11
word before :: sign are namespaces (aka classes). If you want use 2 different classes, you should assign those classes to the proper t2dTrigger object, using its class attribute.
In your case, something like this:
05/10/2010 (2:10 pm)
Hi George,word before :: sign are namespaces (aka classes). If you want use 2 different classes, you should assign those classes to the proper t2dTrigger object, using its class attribute.
In your case, something like this:
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TutorialNote1";
useMouseEvents = "1";
Position = "12.145 6.667";
size = "5.709 6.667";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "4";
};
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TutorialNote2";
useMouseEvents = "1";
Position = "21.721 6.779";
size = "6.559 6.441";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "5";
};
#12
Only thing different is use mouse events, is that relevant?
Sorry for all this :P
Thanks in advance... Again :)
05/10/2010 (2:28 pm)
Yeah, I think I've done that - correctly too. I'll let you take a look:new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TutorialNote1";
Position = "-1798.610 -242.000";
size = "5.000 16.000";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "23";
};
new t2dTrigger() {
canSaveDynamicFields = "1";
class = "TutorialNote2";
Position = "-1764.996 -233.000";
size = "5.000 16.000";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
mountID = "24";
};The first message still works, it's only the second one.Only thing different is use mouse events, is that relevant?
Sorry for all this :P
Thanks in advance... Again :)
#13
no, useMouseEvents should affect only mouse events ^^ I can't see anything wrong here: the only strange parameters are the trigger positions: I suppose you move those triggers because they seems out of camera (or you have set a very big camera)
You should check the incorrect behavior inside a smaller project (try inside the one I sent to you) and, if all works there, then you know the problem is somewhere inside your big project but it's related to something else.
05/11/2010 (6:27 pm)
Hi George,no, useMouseEvents should affect only mouse events ^^ I can't see anything wrong here: the only strange parameters are the trigger positions: I suppose you move those triggers because they seems out of camera (or you have set a very big camera)
You should check the incorrect behavior inside a smaller project (try inside the one I sent to you) and, if all works there, then you know the problem is somewhere inside your big project but it's related to something else.
Torque Owner George Fairs