Difference between revisions of "$puttok"

From Scriptwiki
Jump to: navigation, search
 
(Replaced example to stop users using findtok and puttok to replace and added also see reptok section.)
Line 7: Line 7:
 
  [[echo]] -ag $puttok(This is a moo, test, 4, 32)
 
  [[echo]] -ag $puttok(This is a moo, test, 4, 32)
 
This example replaces ''moo'' with ''test'' and therefor echo's ''This is a test''.
 
This example replaces ''moo'' with ''test'' and therefor echo's ''This is a test''.
  [[var]] %text = This is a moo
+
  [[var]] %botinfo = Nick JoinTime Admin
  var %replacefrom = moo
+
  [[If-Then-Else|if]] (!%admin) { [[set]] %botinfo $puttok(%users.1,[[$nick]],3,No) }
var %replaceto = test
+
  else { [[set]] %botinfo $puttok(%users.1,[[$nick]],3,Yes) }
  %text = $puttok(%text, %replaceto, [[$findtok]](%text, %replacefrom, 1, 32), 32)
+
  echo -ag %botinfo
  echo -ag %text
+
This example depending upon if ''%admin'' is [[$true]] or [[$false]] sets the third word in ''%botinfo'' to ''Yes'' or ''No''.
This example echo's ''This is a test'' too, as $findtok() returns the position of ''moo'' in the string and $puttok replaces this token with ''test''.
+
'''Varibles set:'''
 
+
''%gather_info = L,Q,G,O,F,S,P,Dana myserver.com 12345 10''   ;;Players Server Port MaxPlayers
 +
 +
on *:[[On_Part|PART]]:#GatherChan: {
 +
  var %tmp.nicks = [[$gettok]](%gather_info,1,32)              ;;Get nicknames into a temporary variable.
 +
  if ([[$istok]](%tmp.nicks,$nick,44)) {                        ;;If nickname is in gather ...
 +
    set %tmp.nicks [[$remtok]](%tmp.nicks,$nick,44)            ;;  remove them.
 +
    set %gather_info $puttok(%gether_info,%tmp.nicks,1,32)  ;;Update ''%gather_info'''s first token with the players that are left.
 +
  }
 +
}
 +
== Also see ==
 +
[[$reptok]]
 
[[Category:Token Identifiers]]
 
[[Category:Token Identifiers]]

Revision as of 21:06, 17 October 2005

Overwrites the Nth token in text with a new token.

$puttok(text,token,N,C)

Note that you can specify a negative N.

Example

echo -ag $puttok(This is a moo, test, 4, 32)

This example replaces moo with test and therefor echo's This is a test.

var %botinfo = Nick JoinTime Admin
if (!%admin) { set %botinfo $puttok(%users.1,$nick,3,No) }
else { set %botinfo $puttok(%users.1,$nick,3,Yes) }
echo -ag %botinfo

This example depending upon if %admin is $true or $false sets the third word in %botinfo to Yes or No.

Varibles set:
%gather_info = L,Q,G,O,F,S,P,Dana myserver.com 12345 10   ;;Players Server Port MaxPlayers

on *:PART:#GatherChan: {
  var %tmp.nicks = $gettok(%gather_info,1,32)               ;;Get nicknames into a temporary variable.
  if ($istok(%tmp.nicks,$nick,44)) {                        ;;If nickname is in gather ...
    set %tmp.nicks $remtok(%tmp.nicks,$nick,44)             ;;   remove them.
    set %gather_info $puttok(%gether_info,%tmp.nicks,1,32)  ;;Update %gather_info's first token with the players that are left.
  }
}

Also see

$reptok