Jump to content

F_RandMes suggestion


nanakiwurtz

Recommended Posts


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

I think it could be simplified like this:

function    script    F_RandMes    {

    set .@i, getargcount();

    return getarg(rand(1,.@i));

}

What do you think? /ok
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

It should be : 

function    script    F_RandMes    {
    set .@i, getargcount();
    return getarg(rand(0,.@i));
}

since the first argument will be remove ( number of arguments ) 

callfunc("F_RandMes",1129,1222,1163,1357,1360,1522,1811,1410);
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

function script F_RandMes {
set .@i, getargcount()-1;
return getarg(rand(0,.@i));
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

Ahh i forgot that it will start from 0 haha

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

You can use pull requests for something like this, you know. :P Want to give it a shot?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Is there any specific reason a variable is initialized for only one use?

Wouldn't 

function script F_RandMes {
    return getarg(rand(0, (getargcount() - 1)));
}

 

be better?

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

Why not, your way is easier to use.

Also F_RandMes is only used in F_Hi and F_Bye functions in a clean version, it's not a lot of work (lol) to change them

//////////////////////////////////////////////////////////////////////////////////
// *** Function "F_Hi"
//////////////////////////////////////////////////////////////////////////////////
//returns random HELLO message

function	script	F_Hi	{
	return callfunc("F_RandMes",5,"Hi!","Hello!","Good day!","How are you?","Hello there.");
}


//////////////////////////////////////////////////////////////////////////////////
// *** Function "F_Bye"
//////////////////////////////////////////////////////////////////////////////////
//returns random BYE message

function	script	F_Bye	{
	return callfunc("F_RandMes",6,"Bye. See you again.","Later.","Goodbye.","Good luck!","Have a nice day!","Byebye!!!");
}
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2345
  • Joined:  10/28/11
  • Last Seen:  

even simpler ..??

function script F_RandMes {
    return getarg( rand( getargcount() ) );
}

but i think the name should change too ? since it's not only for "mes"

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

Dang... I didn't realize that it only needs a single line...

Does making a 'Pull Request' means that I have to make a fork?

TBH I don't know how :P

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

Lol 1 rep for ya @Emistry :D. Why not make it simply F_Rand or even F_Random :3

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   381
  • Joined:  02/03/12
  • Last Seen:  

I think it could be simplified like this:

function    script    F_RandMes    {
    set .@i, getargcount();
    return getarg(rand(1,.@i));
}
What do you think? /ok

 

Nanakiwurtz, I think this is very cool... You're awesome to request this :)

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Implemented in 66a2bfd.

Link to comment
Share on other sites

×
×
  • Create New...