PDA

View Full Version : How to use message box's and Input Query's!



rj
04-26-2013, 11:20 PM
Officer Barbrady's tutorial on using message box's and input query's!



Hello, I am going to show you how to use message box with simba!

Table of Contents

-What is a message box?
-Types
-Basics
-Input Query
-Advanced



What is a message box?

A message box is a little cute notification like this:
http://i39.tinypic.com/2a6o95g.png

Code:
Procedure Easy_setup;
var
Reply:Integer;
Begin
Reply := MessageBox('Hello! Welcome to the message box tutorial!', 'Message box tutorial',4);
end;
begin
Easy_setup;
end.

Message box's can help make your script easy to use, especially when combined with input query's
Types of message box's


Now you don't only have to use the message box from above. There are many different types! The way you change which box is it it changing the number at the end of the function:

Reply := MessageBox('Hello! Welcome to the message box tutorial!', 'Message box tutorial',4);


See the 4? If you change that to 3 it will give you a message message box! Here are all the different types:

1:http://i44.tinypic.com/t06r60.png
2:http://i44.tinypic.com/ayvwn4.png
3:http://i42.tinypic.com/332c93q.png
4:http://i39.tinypic.com/2a6o95g.jpg
5:http://i42.tinypic.com/a6051.png
6:http://i41.tinypic.com/2ecdxqq.png
8:http://i40.tinypic.com/rvccg4.png

[5 &7 are the same]

Once you get higher in the numbers you can different images beside the message like here:

http://i41.tinypic.com/2v2w3n8.png


Basics

When you press a button on the message box it returns a Integer, like here:

Reply := MessageBox('Hello! Welcome to the message box tutorial!', 'Message box tutorial',4);

If I choose yes, then it returns 6, if I choose no then it returns 7. I am not sure why it returns these numbers specifically -.- but that is just the way it works. You can debug this by using:

writeln(ToStr(Reply))

After you choose the option it will output the number the option returns.

Now, you want it to do something! First, there are only 2 possible returns it will give and we will be using a case statement that will execute some code depending on what you pick. Let's begin, first, since above I declared "Reply" as a Integer, I will need to make a case of Reply:
case (Reply) of

Next, since it chooses 6 for yes and 7 for no we will add in some code for it to do depending on whether reply is 6 or 7:

case (Reply) of
6: Writeln('Yes!');
7: Writeln('No!');
end;

As you can see, if Reply is 6 then it outputs yes, if reply is 7 then it outputs no. Now let's make it a little bit more complicated, lets say if you choose yes you want it to go to a procedure and if you choose no you want it to do nothing. That is fairly simple:

Procedure Yes;
begin
writeln('yes');
end;
Procedure Easy_setup;
var
Reply:Integer;
Begin
Reply := MessageBox('Hello! Welcome to the message box tutorial!', 'Message box tutorial',4);
//writeln(ToStr(Reply))
case (Reply) of
6: Yes;
7: exit;
end;
end;
begin
Easy_setup;
end.

If Reply is 6 then it goes to the procedure "Yes;" if it is 7 then it will "exit" and do nothing.


Input Query

Input query is a little box that shows up that asks the user to put in some info like so:

http://i44.tinypic.com/35d3q0k.png

(InputQuery('Test', 'Test:' , TestString));

In order for it to work you have to declare a variable as a string in order for it to save what ever the user typed in to save to that string:

program Input;
Var
TestString:string;
begin
(InputQuery('Test', 'Test:' , TestString));
end.

Now let's make it display what the user just put in:

program Input;
Var
TestString:string;
begin
(InputQuery('Test', 'Test:' , TestString));
writeln(TestString);
end.



Advanced

Now I will teach you how to actually make this useful in a script. This is actually not hard at all. We are going to combine the use of message box's and input query!

Now, let's say you want simba to check if the player entered their username, but first ask if the player wants to use your "setup":

Procedure Easy_setup;
var
Reply:Integer;
Begin
Reply := MessageBox('Would you like to use easy-setup?', 'Easy setup',4);
case (Reply) of
7: exit;
end;
end;


As you can see I did not include the case of 6, that is because if they choose "yes" it will just move on. If you feel uncomfortable with doing this than you can just do:

case (Reply) of
6: wait(1);
7: exit;
end;


If the user choose's yes then it will continue on with the next lines of code, if they choose no then it will exit the procedure. Now we want it to check if the user entered their username:

if Players[0].Name = '' then

Now you enter your Message box:

Reply := MessageBox('You have not entered a username would you like to enter in now?', 'Easy setup',4);

And if the user choose's yes then it will bring up the input Query:

6: (InputQuery('Username', 'Username:' , Players[0].Name));

As you can see it is saving what the user entered in the username variable!

Whole procedure:

Procedure Easy_setup;
var
Reply:Integer;
Begin
Reply := MessageBox('Would you like to use easy-setup?', 'Easy setup',4);
case (Reply) of
6: wait(1);
7: exit;
end;
if Players[0].Name = '' then
begin
Reply := MessageBox('You have not entered a username would you like to enter in now?', 'Easy setup',4);
case (Reply) of
6: (InputQuery('Username', 'Username:' , Players[0].Name));
end;
end;
end;









I hope this tutorial helped, and that you might use it in your script for fun or to make it more easy to use!