Help😳 Making a random script...

Posts 1–9 of 9 · Page 1 of 1
😳 Making a random script...
Hello... So i was making a completly useless script just to learn a bit, but it aint working and as it is written in javascript its reaaalllyyy hard to understand whats wrong.
Code:
var ID_PLAYERTEXT = $.findPacketId("PLAYERTEXT");
var ID_TEXT = $.findPacketId("TEXT");

var spamt = "NOT SET!";

function onClientPacket(event) {
	var packet = event.getPacket();
	switch (packet.id()) {
	case ID_PLAYER_TEXT:
        {
            var text = packet.text.toLowerCase();

            if (text == "/spam") {
				event.cancel();
                var textp = $.createPacket(ID_PLAYERTEXT);
				textp.text = spamt;
				$.sendToServer(textp);
            }
            break;
        }
	}
	
}

function onServerPacket(event) {
	var packet = event.getPacket();
	switch (packet.id()) {
		 case ID_TEXT:
        {
		var text = packet.text;
		
            if (text.length > 0) {
 
			var spamt = text;
 
            }
        }
	}
}

function spam() {

    var textp = $.createPacket(ID_PLAYERTEXT);
    textp.text = spamt;
    $.sendToServer(textp);
}
If i write /spam in chat it will say command not recognised even through i used "event.cancel()".
You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).
You defined variable:
Quote Originally Posted by supergovs View Post
var ID_PLAYERTEXT = $.findPacketId("PLAYERTEXT");
But used it with extra _:
Quote Originally Posted by supergovs View Post
case ID_PLAYER_TEXT:
__________________________________________

Quote Originally Posted by Rebel01390 View Post
You cannot compare strings with ==, You must use <string>.equals(<string>) or <string>.equalsIgnoreCase(<string>).
You can compare strings with == on realm relay script
__________________________________________

Also
Quote Originally Posted by supergovs View Post
function spam() {

var textp = $.createPacket(ID_PLAYERTEXT);
textp.text = spamt;
$.sendToServer(textp);
}
is never called. Anyways the script doesn't make sense even if these mistakes were corrected
Code:
case ID_PLAYER_TEXT:
        {
            var text = packet.text.toLowerCase();

            if (text == "/spam") {
                event.cancel();
                var textp = $.createPacket(ID_PLAYERTEXT);
                textp.text = spamt;
                $.sendToServer(textp);
            }
            break;
Not familiar with RR but.. If you are have a PLAYERTEXT packet, why not just change the text ? Why creating another PLAYERTEXT ?
Quote Originally Posted by JustAnoobROTMG View Post
Code:
case ID_PLAYER_TEXT:
        {
            var text = packet.text.toLowerCase();

            if (text == "/spam") {
                event.cancel();
                var textp = $.createPacket(ID_PLAYERTEXT);
                textp.text = spamt;
                $.sendToServer(textp);
            }
            break;
Not familiar with RR but.. If you are have a PLAYERTEXT packet, why not just change the text ? Why creating another PLAYERTEXT ?
You are correct, there's no need to cancel a packet only to create the same packet again.
Both ways work but changing the existing packet makes more sense.
Quote Originally Posted by CrazyJani View Post
You can compare strings with == on realm relay script
You should educate yourself on what the == operator does, it's a good programming habit to never use it for strings
Quote Originally Posted by Knorrex View Post
You should educate yourself on what the == operator does, it's a good programming habit to never use it for strings
Depends on what language you use. I know AS3 "==" does what the user think it does with strings but java equates the actual object instead of the value of the string.
Quote Originally Posted by nilly View Post
Depends on what language you use. I know AS3 "==" does what the user think it does with strings but java equates the actual object instead of the value of the string.
Well , while the java == will check for memory address, js == does type coercion and value comparison, one might say there's a small chance of unexpected behaviour, but yeah, I'll keep using equals for good habit
Quote Originally Posted by Knorrex View Post
Well , while the java == will check for memory address, js == does type coercion and value comparison, one might say there's a small chance of unexpected behaviour, but yeah, I'll keep using equals for good habit
There is no equals in AS3. Afaik, one has to use == to compare two strings. Of course AS3 is more of an exception than the rule.
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us