Author Topic: Help with a script im making  (Read 1704 times)

Im making sort of a game with the chat and I need help with this.

Im trying to make it so that one specific person will be chosen at random to be the murderer, but I dont know if im doing it right.
The variable im referencing to is the %murder = %s[%selected]
Code: [Select]
package game
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
    {
//VARIABLES//

%s1 = "Mr. Patrith";
%s2 = "Ms. Funkleberry";
%s3 = "Simon Ghinly";
%s4 = "Jon Verning";
%s5 = "Alvin Feldgim";
%s6 = "Martin Snow";

%selected = getrandom(1,6)
%murderer = %s[%selected]
//ENDVARIABLES//

parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

if(%msg $= "!murder")
{
NewChatSO.addLine("<color:00ff00>INDEX");
NewChatSO.addLine("<color:ffffff>!HELP/INFO");
NewChatSO.addLine("<color:ffffff>!COMMANDS");
NewChatSO.addLine("<color:ffffff>!PLAY");
}
if(%msg $= "!Help/info")
{
NewChatSO.addLine("<color:00ff00>GUIDE");
NewChatSO.addLine("<color:ffffff>You are J. V. Wattingsworth, an experienced detective. When a murder comes about, it is up to you to solve it.");
NewChatSO.addLine("<color:ffffff>Examine the clues and question the suspects to find the murderer.");
}
if(%msg $= "!play")
{
NewChatSO.addLine("<color:00ff00>STORY");
NewChatSO.addLine("<color:ffffff>You are walking down the hotel hallway when you hear a scream.");
NewChatSO.addLine("<color:ffffff>You rush to the scene and find a body, freshly murdered.");
NewChatSO.addLine("<color:ffffff>Within hours you have collected enough evidence and suspects/witnesses. Now you just need to solve the case.");
NewChatSO.addLine("<color:00ff00>Type !start to begin");
}
if(%msg $= "!start")
{
NewChatSO.addLine("<color:00ff00>GAME");
NewChatSO.addLine("<color:ffffff>Type !suspects to see the suspects");
NewChatSO.addLine("<color:ffffff>Type !evidence to see the evidence");
NewChatSO.addLine("<color:ffffff>Type !examine evidencehere to examine the evidence")
}
if(%msg $= "!suspects")
{
NewChatSO.addLine("<color:00ff00>SUSPECTS");
NewChatSO.addLine("<color:ffffff>Mr. Patrith");
NewChatSO.addLine("<color:ffffff>Ms. Funkleberry");
NewChatSO.addLine("<color:ffffff>Simon Ghinly";");
NewChatSO.addLine("<color:ffffff>Jon Verning";");
NewChatSO.addLine("<color:ffffff>Alvin Feldgim";");
NewChatSO.addLine("<color:ffffff>Martin Snow";");
}


}
};
activatepackage(game);

To me it looks like you need more practice with torquescript syntax.  You are missing quite a few semicolons ( ; ) and have broken string syntax.

Code: [Select]
NewChatSO.addLine("<color:ffffff>Simon Ghinly";");
Will not compile, since you are ending the string and then have an extra ;" which is not valid.

Also note that this function will be called every time someone sends a message in chat, and will not filter it to be just your messages.

To me it looks like you need more practice with torquescript syntax.  You are missing quite a few semicolons ( ; ) and have broken string syntax.

Code: [Select]
NewChatSO.addLine("<color:ffffff>Simon Ghinly";");
Will not compile, since you are ending the string and then have an extra ;" which is not valid.

Also note that this function will be called every time someone sends a message in chat, and will not filter it to be just your messages.
I noticed the semicolon thing yesterday, but how would I make it to be just my messages?
and how would I make the murderer be randomized?

I noticed the semicolon thing yesterday, but how would I make it to be just my messages?
and how would I make the murderer be randomized?
For the name you could do if(%name $= $Pref::Player::NetName). But I suggest you use an entirely different function instead(NMH_Type::Send(%this)).

For the name you could do if(%name $= $Pref::Player::NetName). But I suggest you use an entirely different function instead(NMH_Type::Send(%this)).

Gives me an error when I replace the function

Gives me an error when I replace the function
Than you did it wrong. It will also take some modifying after you replace it. You will no longer need to check if it's you, you will need to do %msg = %this.getValue(); and you will want to put all chat messages on a short delay. newChatSO.schedule(milliseconds, addLine, "Stuff");
« Last Edit: February 13, 2014, 07:37:23 AM by jes00 »

Than you did it wrong. It will also take some modifying after you replace it. You will no longer need to check if it's you, you will need to do %msg = %this.getValue(); and you will want to put all chat messages on a short delay. newChatSO.schedule(milliseconds, addLine, "Stuff");
ok that works.

Now how would I get it to randomize the murderer?

ok that works.

Now how would I get it to randomize the murderer?
Same way that your doing it, but do it when the player says !start and use global variables instead.

Same way that your doing it, but do it when the player says !start and use global variables instead.
Posting this on free time in school, but apparently the message filter function doesn't work still.
Do I replace all of the function or put it after the function?

Posting this on free time in school, but apparently the message filter function doesn't work still.
Do I replace all of the function or put it after the function?
What do you mean?

What do you mean?
do I change this
Code: [Select]
function NMH_Type::Send(%this)
    {

parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
to this
Code: [Select]
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
    {

parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

or change it to this

Code: [Select]
NMH_Type::Send(%this)
    {

parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

Well, seeing as in the third code block every single one of the variables you're referencing are undefined (%a, %b, %c, %fmsg, %cp, %name, %cs, %msg) that one can't possibly be it. So, that leaves the second code block.

Well, seeing as in the third code block every single one of the variables you're referencing are undefined (%a, %b, %c, %fmsg, %cp, %name, %cs, %msg) that one can't possibly be it. So, that leaves the second code block.
so I would remove the parent(variablesere) and that would fix my problem?
but then what code block would I use?

EDIT: Defining the murderer gives me the following error
Code: [Select]
//VARIABLES//
$s1 = "Mr. Patrith";
$s2 = "Ms. Funkleberry";
$s3 = "Simon Ghinly";
$s4 = "Jon Verning";
$s5 = "Alvin Feldgim";
$s6 = "Martin Snow";
$selected = getRandom(1,6);
$murderer = $s[selected]
//ENDVARIABLES//

package ##g##ame
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
    {

please note that this isnt the entire script
« Last Edit: February 13, 2014, 05:59:04 PM by Gsterman »

The error that's being displayed is because you didn't type function before NMH_Type::send. Also, in your if statement, you're looking for if(%this.getValue() $= "hi"). Also, you forgot to parent: parent::send(%this);

This code will only work for your own messages. Is that intended?


You changed the code out. Which one is it? The problem with this one is that you forgot a semicolon (;) after $murderer = $s[%selected] (you also forgot the % before selected).
« Last Edit: February 13, 2014, 06:00:39 PM by $trinick »

The error that's being displayed is because you didn't type function before NMH_Type::send. Also, in your if statement, you're looking for if(%this.getValue() $= "hi"). Also, you forgot to parent: parent::send(%this);

This code will only work for your own messages. Is that intended?
yupee, can you read my new edit because im having problems with that.
sorry im bad at this, im not that good at torque and rarely even code.