Author Topic: How do I broadcast a random chat message?  (Read 1664 times)

I want to have a thing where it randomly selects one of six messages and broadcasts it in the chat, but I cant figure it out.

Code: [Select]
%m0 = "Message1 is stupid.";
%m1 = "the below statement is true";
%m2 = "the above statement is false";
%m3 = "The two messages above are false.";
%m4 = "Message5 is stupider.";
%m5 = "All of the above messages are false.";

%selected = mFloatLength(getRandom()*6,0);
messageAll('', $m[%selected]);

Note: assign proper names and place inside a function

Code: [Select]
%m0 = "Message1 is stupid.";
%m1 = "the below statement is true";
%m2 = "the above statement is false";
%m3 = "The two messages above are false.";
%m4 = "Message5 is stupider.";
%m5 = "All of the above messages are false.";

%selected = mFloatLength(getRandom()*6,0);
messageAll('', $m[%selected]);

Note: assign proper names and place inside a function

And be sure not to confuse variable scopes.

And be sure not to confuse variable scopes.
I changed the globals to locals. OP should be able to debug.

The idea of coding help is to help the guy, not post broken code and send him on a little quest to find the problem.

(OP, the $m on the last line should be changed to %m.)

And another protip; you can use getRandom with arguments so you don't have to do silly things like play with mFloatLength:

Code: [Select]
getRandom(1,6);
Will return a number between 1 and 6 inclusive.
« Last Edit: May 27, 2013, 06:48:42 PM by Ephialtes »

The idea of coding help is to help the guy, not post broken code and send him on a little quest to find the problem.

(OP, the $m on the last line should be changed to %m.)

And another protip; you can use getRandom with arguments so you don't have to do silly things like play with mFloatLength:

Code: [Select]
getRandom(1,6);
Will return a number between 1 and 6 inclusive.
For some reason messageall wont work.
Also, could you perhaps make this excecutable by command?

For some reason messageall wont work.
MessageAll('', %var);
               ^ those are single quotes, don't touch them.

MessageAll('', %var);
               ^ those are single quotes, don't touch them.

2 separate apostrophes '' you mean.

MessageAll('', %var);
               ^ those are single quotes, don't touch them.


stuff you can put in the single quotes (default)
Code: [Select]
MsgClientInYourMiniGame
MsgClientJoin
MsgConnectionError
MsgYourDeath
MsgYourSpawn
MsgError
MsgAdminForce
MsgClearBricks
MsgPlantError_Overlap
MsgPlantError_Float
MsgPlantError_Unstable
MsgPlantError_Buried
MsgPlantError_Stuck
MsgPlantError_TooFar
MsgPlantError_Teams
MsgPlantError_Flood
MsgPlantError_Limit
MsgPlantError_TooLoud
MsgPlantError
MsgItemPickup
MsgDropItem
MsgClearInv
MsgHilightInv
MsgEquipInv
MsgDeEquipInv
MsgSetInvData
MsgStartTalking
MsgStopTalking
MsgUploadStart
MsgUploadEnd
MsgProcessComplete
MessageAll('MsgAdminForce',"Hi");

if you want to add one, add this in a client
addMessageCallback('WhateverYouWant',nameOfFunction);
nameOfFunction will be called when you messageAll('WhateverYouWant',"Meow");

You can also do this:
messageAll('','%1 is a %2',"Marble","cat");
and it will message everyone
"Marble is a cat"
the '%1' and '%2' represent variables you put into the messageAll or Messageclient
there is also
MessageAllExcept(%client,~);