(Solved)GrimQuest registration issues

Started by Construed, Mon 28/10/2013 14:50:21

Previous topic - Next topic

Construed

awesome! It seems to work great!
thanks a mill crimson, I really appreciate you taking the time to help!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Crimson Wizard

#21
Nice!

To make things better, you should make the "badString" a global variable and create it on game start to avoid repeating this process during client-server communications (because that may slow them).

To do so declare the variable at the top of the script:
Code: ags

String NickServ_BadString; // you may invent better name, of course

Make a small function that creates this string:
Code: ags

String CreateNickServBadString()
{
   String badString = "If this is your nickname, type /msg NickServ ";
   badString = badString.AppendChar(2);
   badString = badString.Append("IDENTIFY");
   badString = badString.AppendChar(2);
   badString = badString.Append(" <password>");
   return badString;
}


Initialize the string in "game_start" function:
Code: ags

NickServ_BadString = CreateNickServBadString();


EDIT: I forgot you can type special chars other way, using "%c" tag in string formatting:
Code: ags

NickServ_BadString = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);

You won't need CreateNickServBadString function in this case.


And use it in the previous code:
Code: ags

if (ircFrom == "NickServ")
{
   String newString = ircMessage;
   if (newString == NickServ_BadString)
      newString = "Loading...";
   Display(newString);
}


Something like that...

Construed

#22
Even better!
Thank you so much, I'm trying my best to avoid latency issues and this works great!
You are an AGS guru indeed!
-J

Edit:
Code: ags

NickServ_BadString = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);

Very nice!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

Hey, I tried to add a secondary string replace like this:
Code: ags

NickServ_BadString = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString2 = String.Format("Type /msg NickServ HELP %cIDENTIFY%c for more information", 2, 2);



Code: ags

if (ircFrom == "NickServ")
{
   String newString = ircMessage;
   String newString2 = ircMessage;
   
   if (newString == NickServ_BadString)
      newString = "Loading...";
      Display(newString);
 
   if (newString2 == NickServ_BadString2)
      newString2 = "Please try to register again";
      Display(newString2);

  
}


But it didn't work and it ruined the effect of the first one, If i remove it works fine still, but anyone have any idea how I add multiple of these string replacements?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Crimson Wizard

#24
You do not need two "newString" variables. If you need to do same action in two or more cases, combine conditions with OR (||) operator:

Code: ags

if (ircFrom == "NickServ")
{
   String newString = ircMessage;
   
   if (newString == NickServ_BadString || newString == NickServ_BadString2)
      newString = "Loading...";
   Display(newString);
}


Now, assuming there may be more "bad" strings, it is better to make an array of "bad" strings instead, and check for every element of that array.
Declaration:
Code: ags

#define TOTAL_BAD_STRINGS 2 // increase this if you need more
String NickServ_BadString[TOTAL_BAD_STRINGS];

In game_start():
Code: ags

NickServ_BadString[0] = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString[1] = String.Format("Type /msg NickServ HELP %cIDENTIFY%c for more information", 2, 2);

Replacing bad strings:
Code: ags

if (ircFrom == "NickServ")
{
   String newString = ircMessage;

   // Compare with all bad strings and replace if needed
   int bad = 0;
   while (bad < TOTAL_BAD_STRINGS)
   {
      if (newString == NickServ_BadString[bad])
      {
         // bad string matched! replace
         newString = "Loading...";
         // since we do not need to check any more, this trick will force the loop to end prematurely
         bad = TOTAL_BAD_STRINGS;
      }
      else
         bad++; // increase index by one, will try next bad string next time
   }

   Display(newString);
}

Construed

Man this is some VERY awesome code and I can't thank you enough for sharing it with me!
I owe you big time!
One question though, Is it possible to assign different messages to the different NickServ_BadString's?

Thanks a million my friend, and please let me know if you need any graphics, web design, coding done, or anything else done! I really appreciate your time!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Crimson Wizard

Quote from: Construed on Wed 30/10/2013 00:18:39
One question though, Is it possible to assign different messages to the different NickServ_BadString's?
Can you elaborate?

Construed

Code: ags

NickServ_BadString[0] = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString[1] = String.Format("Type /msg NickServ HELP %cIDENTIFY%c for more information", 2, 2);

Say if the string = badstring0 it could display "loading...."
but if the string = badstring1 it could display "click to continue...."
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Crimson Wizard

Ooh. In such case you would need a Map. AGS does not have such built-in class, but you can emulate that (sort of) by using the struct that holds two strings: bad one and good one (a replacement).

Declaration:
Code: ags

// Declare the struct
struct StringReplacement
{
    String Bad;
    String Good;
};

// Declare the array of structs:
#define TOTAL_BAD_STRINGS 2 // increase this if you need more
StringReplacement NickServ_BadString[TOTAL_BAD_STRINGS];


Setup values in pairs (bad/good):
Code: ags

NickServ_BadString[0].Bad = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString[0].Good = "Loading...";
NickServ_BadString[1].Bad = String.Format("Type /msg NickServ HELP %cIDENTIFY%c for more information", 2, 2);
NickServ_BadString[1].Good = "Click to continue...";


New replacement code (only shown the part that has to be modified):
Code: ags

<...>
      if (newString == NickServ_BadString[bad].Bad)
      {
         // bad string matched! replace
         newString = NickServ_BadString[bad].Good;
<...>
}

Construed

It works like a well oiled machine!
Code: ags

// Declare the struct
struct StringReplacement
{
    String Bad;
    String Good;
};
 
// Declare the array of structs:
#define TOTAL_BAD_STRINGS 4 // increase this if you need more
StringReplacement NickServ_BadString[TOTAL_BAD_STRINGS];


//--------------------------------------------------------------------------------
function game_start() {
  
NickServ_BadString[0].Bad = String.Format("If this is your nickname, type /msg NickServ %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString[0].Good = "Loading...";
NickServ_BadString[1].Bad = String.Format("Type /msg NickServ HELP %cIDENTIFY%c for more information", 2, 2);
NickServ_BadString[1].Good = "Click to continue...";
NickServ_BadString[2].Bad = String.Format("Syntax: %cIDENTIFY%c <password>", 2, 2);
NickServ_BadString[2].Good = "Click to continue...";
NickServ_BadString[3].Bad = String.Format("Type %c/msg NickServ HELP IDENTIFY%c for more information", 2, 2);
NickServ_BadString[3].Good = "Please try again";


Code: ags

     if (ircFrom == "NickServ")
{
   String newString = ircMessage;
 
   // Compare with all bad strings and replace if needed
   int bad = 0;
   while (bad < TOTAL_BAD_STRINGS)
   {
           if (newString == NickServ_BadString[bad].Bad)
      {
         // bad string matched! replace
         newString = NickServ_BadString[bad].Good;
         // since we do not need to check any more, this trick will force the loop to end prematurely
         bad = TOTAL_BAD_STRINGS;
      }
      else
         bad++; // increase index by one, will try next bad string next time
   }
 
   Display(newString);
}

Many thanks Crimson!!
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk