Help - Dialog System using GUI
by Romulo Diniz Filippini · in Torque Game Builder · 03/22/2011 (10:11 am) · 15 replies
Hi guys.
I'm trying to make up a dialog system into this point'n'click game I'm trying to make, but is is proving to be a insanely difficult task since, above all, I'm very noob both with programming and with TGB, and cause there is not many docs or tutos regarding the GUI builder.
I have tried alone for a couple weeks, but was unsuccessuful.
What I have now is two dialog frames made with GuiBitmapCtrl objects, and as their children two GuiTextCtrl objects as follows:
When I try to call it with a simple:
It tells that no such object as "Dialog" was found...
After that I've done many GUI tutorials and tried to change their function to make them call up my dialog frame in game, and again fail =/
Until now I have two huge problems:
1 - How implement a function that calls the chat frame with a OnMouseDown command with specific targets, my npcs in this case.
2 - How make it read external txt or xml files where the dialogs are stored and more important, how make it read only the lines reagarding to that specific npc, using some kind of ID or something.
The third problem would be using GuiMLtextControl to make an mutiple answer choice for the player, but, having two big problems such these, I'm tossing that one aside for now, till I understand better how all this stuff works.
I know that the codes for that system must be gigantic, but where I really need help for now is at logics area and maybe some direction at the code.
Thanks in advance for the attention
I'm trying to make up a dialog system into this point'n'click game I'm trying to make, but is is proving to be a insanely difficult task since, above all, I'm very noob both with programming and with TGB, and cause there is not many docs or tutos regarding the GUI builder.
I have tried alone for a couple weeks, but was unsuccessuful.
What I have now is two dialog frames made with GuiBitmapCtrl objects, and as their children two GuiTextCtrl objects as follows:
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(Dialog) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiBitmapCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "10 1";
Extent = "1000 250";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
bitmap = "C:/Documents and Settings/Thiago/Desktop/OPE/resources/elements/TALKbox.png";
wrap = "0";
new GuiTextCtrl(npcchat) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "64 46";
Extent = "881 150";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
text = "hohoho TESTE!";
maxLength = "1024";
};
};
new GuiBitmapCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "10 519";
Extent = "1000 250";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "C:/Documents and Settings/Thiago/Desktop/OPE/resources/elements/TALKbox.png";
wrap = "0";
new GuiTextCtrl(playerchat) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTextProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "65 45";
Extent = "881 150";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
text = "teste duplo";
maxLength = "1024";
};
};
};
//--- OBJECT WRITE END ---When I try to call it with a simple:
function mainMenuGui::chat(%this)
{
// open the options menu up!
if(!Dialog.isAwake())
{
// tell the options menu to get ready
Dialog.initialize();
// display the options menu
Canvas.pushDialog(Dialog);
}
// close the options menu
Canvas.popDialog(%this);
}It tells that no such object as "Dialog" was found...
After that I've done many GUI tutorials and tried to change their function to make them call up my dialog frame in game, and again fail =/
Until now I have two huge problems:
1 - How implement a function that calls the chat frame with a OnMouseDown command with specific targets, my npcs in this case.
2 - How make it read external txt or xml files where the dialogs are stored and more important, how make it read only the lines reagarding to that specific npc, using some kind of ID or something.
The third problem would be using GuiMLtextControl to make an mutiple answer choice for the player, but, having two big problems such these, I'm tossing that one aside for now, till I understand better how all this stuff works.
I know that the codes for that system must be gigantic, but where I really need help for now is at logics area and maybe some direction at the code.
Thanks in advance for the attention
#2
I'll see if the problem was not putting the exec function on my main.cs and reply back my results.
The the tip about return statement was very valuable, I'll include this immediately.
03/22/2011 (11:57 am)
Many thanks for the propmt reply William!I'll see if the problem was not putting the exec function on my main.cs and reply back my results.
The the tip about return statement was very valuable, I'll include this immediately.
#3
Can't believe how could I forget something so simple, and also do not be able to figure out by the system error msg. Gosh.
Now my next problem is to allow my custom mouse pointer to move after calling the chat frame.
It was built as a simple object inside the level builder and implemented using the code:
I'll have to build this um GUI Builder too? Or there is a way to maintain this feature as it is?
03/22/2011 (1:10 pm)
It worked fine, many thanx William!Can't believe how could I forget something so simple, and also do not be able to figure out by the system error msg. Gosh.
Now my next problem is to allow my custom mouse pointer to move after calling the chat frame.
It was built as a simple object inside the level builder and implemented using the code:
function SceneWindow2D::onMouseMove(%this, %mod, %worldPosition)
{
cursor.setPosition(%worldPosition);
}I'll have to build this um GUI Builder too? Or there is a way to maintain this feature as it is?
#4
Might be what you are looking for.
03/22/2011 (1:18 pm)
Search the scripts for defaultCursor and you can actually create your own cursor image and then set the Torque mouse to use it.Might be what you are looking for.
#5
I've searched the method for changing directly the mouse pointer, it would have worked nicely and simple, but, in my case the cursor is animated, and it changes dinamicaly using onMouseOver functions.
I've found a mod that someone made to implement animated cursors in TGE, but i don't know if it can be converted to TGB, here is the mod: Here.
I'll try to figure out something.
At moment I'm searching for TorqueML references for displaying the texts at chat frames. But I'll try to make them appear one character at time, there is someway to do that?
03/22/2011 (2:37 pm)
Hi Chris and thanks for the response.I've searched the method for changing directly the mouse pointer, it would have worked nicely and simple, but, in my case the cursor is animated, and it changes dinamicaly using onMouseOver functions.
I've found a mod that someone made to implement animated cursors in TGE, but i don't know if it can be converted to TGB, here is the mod: Here.
I'll try to figure out something.
At moment I'm searching for TorqueML references for displaying the texts at chat frames. But I'll try to make them appear one character at time, there is someway to do that?
#6
03/22/2011 (2:45 pm)
Ya, that can probably be ported fairly easily if you have source code. Even by a noob. Not insinuating you are ;)
#7
And don't mind, I've stated at the start of the thread:
Indeed I'm still a noob, but I'm a very motivated one! =D
03/22/2011 (2:50 pm)
So I'll try that later since I do own the pro version =]And don't mind, I've stated at the start of the thread:
Quote:...I'm very noob both with programming and with TGB...
Indeed I'm still a noob, but I'm a very motivated one! =D
#9
The mouse movement problem was because some elements of the UI had modal set as true, forbidding any interaction outside it.
I can store into a variable the text I want to show, however:
But, it doesn't work, it shows only the first message. A syntax error? Should I use a WHILE keyword to allocate various different npcIds/texts?
03/22/2011 (6:25 pm)
Well, it seems that the day is already gone, but with your help I managed to reach this stage!The mouse movement problem was because some elements of the UI had modal set as true, forbidding any interaction outside it.
I can store into a variable the text I want to show, however:
$npcID = 18;
function setNpcText()
{
if ($npcId = 22)
{
%text = ("Success! The npcId value is 22, so this is the right message!");
npcText.setValue(%text);
}
else
{
%text = ("Wrong! The npcId value isn't 22, this the other message!");
}
}But, it doesn't work, it shows only the first message. A syntax error? Should I use a WHILE keyword to allocate various different npcIds/texts?
#10
Some people doing it the other way around, with constant value on the left:
03/23/2011 (3:26 am)
if ($npcId = 22)should be a
if ($npcId == 22)I believe.
Some people doing it the other way around, with constant value on the left:
if(22 == $npcId)This way the code just won't compile with '=' instead of '=='.
#11
EDIT: nevermind... My code tags aren't displaying my code the way I want them to.
Point is. Proper tabbing, your else shouldn't be 2 lines away from your closing if statement, I believe your setValue should be after the else (not inside the if, that's why it only shows for the first half of your if / else.), you should pass the id in as a parameter. name your variables so they are easy to understand.
Consider %npcID_int as a paremeter.
Consider namign the $npcID as $global_npcID so you know it's intended to be a generally accessible variable to whatever needs it.
These are things I do. Everyone has there own... hardcore c++ devs will hate the advice I give. The point is to find something that is easy to understand, looks nice so you can follow it easily, and makes your code self documenting so in 5 years when you reread it it makes some sense what everything is and what you intended it to do.
it's early in the morning and I think I just rambled a whole bunch but I will post it for you to read anyways.
03/23/2011 (5:22 am)
@Romulo - I would also suggest you get into the habit of properly formatting your code to make it easier to read.EDIT: nevermind... My code tags aren't displaying my code the way I want them to.
Point is. Proper tabbing, your else shouldn't be 2 lines away from your closing if statement, I believe your setValue should be after the else (not inside the if, that's why it only shows for the first half of your if / else.), you should pass the id in as a parameter. name your variables so they are easy to understand.
Consider %npcID_int as a paremeter.
Consider namign the $npcID as $global_npcID so you know it's intended to be a generally accessible variable to whatever needs it.
These are things I do. Everyone has there own... hardcore c++ devs will hate the advice I give. The point is to find something that is easy to understand, looks nice so you can follow it easily, and makes your code self documenting so in 5 years when you reread it it makes some sense what everything is and what you intended it to do.
it's early in the morning and I think I just rambled a whole bunch but I will post it for you to read anyways.
#12
Here's my multi-line control:
Because I have a list of text messages queue up, I have the scene control the messages. I've modified my example to still have the scene control the message display, but I have the multi-line control handling the text itself.
Finally, I have the HUDScene.animatePetText function:
Since the GuiMLTextCtrl mark-up has tags, there's code to make sure that tags are read all at once before being placed.
You can fiddle with the "10" in the last line of code to set the speed. That's milliseconds for each character, so this is 100 characters a second.
03/23/2011 (8:58 am)
Here's an example of how I have the GuiMLTextCtrl show the text one character at a time:Here's my multi-line control:
new GuiMLTextCtrl(PetText) {
... misc settings ...
};Because I have a list of text messages queue up, I have the scene control the messages. I've modified my example to still have the scene control the message display, but I have the multi-line control handling the text itself.
function showText( %text )
{
PetText.goalText = %text;
PetText.charIter = 0;
PetText.maxChar = strlen( %text );
HUDScene.schedule( 0, animatePetText );
}Finally, I have the HUDScene.animatePetText function:
function HUDScene::animatePetText()
{
PetText.charIter += 1;
if( getSubStr( PetText.goalText, PetText.charIter - 1, 1 ) $= "<" )
{
while( getSubStr( PetText.goalText, PetText.charIter - 1, 1 ) !$= ">" )
PetText.charIter++;
}
PetText.setText( getSubStr( PetText.goalText, 0, PetText.charIter ) );
PetText.forceReflow();
if( PetText.charIter < PetText.maxChar )
PetText.tick = HUDScene.schedule( 10, animatePetText );
}Since the GuiMLTextCtrl mark-up has tags, there's code to make sure that tags are read all at once before being placed.
You can fiddle with the "10" in the last line of code to set the speed. That's milliseconds for each character, so this is 100 characters a second.
#13
Many thanks for the advices and they are indeed valuable ones! I frequently revisit my old codes when coming up with new ones, so organization could save my life in future. =]
To Mr. William:
That code is very impressive! I'll try putting it on move later. I've read the code with attention trying to understand it, learned about getSubStr, but there are some terms I still don't know like:
strlen()
forceReflow()
tick.
I'll try raid into TDN reference guides for these ones.
Anyway thanks for all the help until now, I believe that some time tomorrow I'll come up with a playble mini-demo.
C ya
03/23/2011 (7:48 pm)
To Mr. Chris:Many thanks for the advices and they are indeed valuable ones! I frequently revisit my old codes when coming up with new ones, so organization could save my life in future. =]
To Mr. William:
That code is very impressive! I'll try putting it on move later. I've read the code with attention trying to understand it, learned about getSubStr, but there are some terms I still don't know like:
strlen()
forceReflow()
tick.
I'll try raid into TDN reference guides for these ones.
Anyway thanks for all the help until now, I believe that some time tomorrow I'll come up with a playble mini-demo.
C ya
#14
And the help of the forum users was indispensable for getting me out of some stuck points!
I'll be posting the download link shortly, I just need some hours of sleep first and to translate the texts to english.
C ya
03/25/2011 (6:11 pm)
Well, this friday I've finished our game mini-demo, well pretty much if you don't pay attention to some minor bugs.And the help of the forum users was indispensable for getting me out of some stuck points!
I'll be posting the download link shortly, I just need some hours of sleep first and to translate the texts to english.
C ya
#15
03/26/2011 (6:57 am)
Congratulations Romulo!
Associate William Lee Sims
Machine Code Games
Also, you don't want to pop your dialog right after the push. Put a return statement right at the end (and inside) your if-statement block. That way when you call "chat" the first time, it'll bring up the popup. When you call it the second time, it'll close it.