mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
Yupyup, me again.

I need to take a variable and use the contents of that variable to make another variable laugh

Example:
$nick = Bob5

/set %name.of.user.Bob5 True

then %name.of.user.Bob5 = True

but let's say I didn't know what $nick was...

Could I do this?:

/set %name.of.user.$nick True (or %var)
or
/set %name.of.user. $+ $nick True (or %var)
or
/set (%name.of.user. $+ $nick) True

would any of those work to produce:

%name.of.user.Bob5 True

Get it?


OR if you don't cant tell me then answer this:

How do I check if a file exists and return true if it exists and false if it doesnt.

Example:

if filename.txt exists
return true
elseif filename.txt does not exist
return false

(not real code, but you get what I want) :P


Thanks guys, you are all a lot of help. The sooner I learn this, the sooner I can be the one helping.

Last edited by BNX; 03/07/05 03:47 AM.
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
You had it, it's /set %name.of.user. $+ $nick

This works because /set will not evaluate what follows it if it's a variable name. So $+ $nick is joined to the literal '%name.of.user.' and the result is set as a variable

When it comes to getting the value, you need to force the $+ $nick to evaluate before the variable name behind it: %name.of.user. [ $+ [ $nick ] ] or $eval($+(%,name.of.user,$nick),2)

Lastly, $isfile returns $true/$false depending on whether a file exists. $isfile(path\file.ext)

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
Thanks


Oh, and if I wanted to call %variable.Bob
But I dont know if Bob created it yet.
if he did, he used - %variable. [ $+ [ $nick ] ]
would I do
%variable.Bob
or
%variable. [ $+ [ Bob ] ]
or
$eval($+(%,variable.,Bob),2)

Last edited by BNX; 03/07/05 04:31 AM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
To acces the variable all 3 of these are the same, the second two are redundent sicne your hardcoding BOB into it.

%variable.Bob
%variable. [ $+ [ Bob ] ]
$eval($+(%,variable.,Bob),2)

if your not hard coding BOB into it, let say your passing it as $1 you can use
%variable. [ $+ [ $1 ] ]
$eval($+(%,variable.,$1),2)

Heres some things to note.
Blue works & Red DOES NOT

set %variable. [ $+ [ $1 ] ] BLAH
echo -a %variable. [ $+ [ $1 ] ]

set %variable. $+ $1 BLAH
echo -a %variable. $+ $1

set $+(%,variable.,$1) BLAH
echo -a $+(%,variable.,$1)

set $eval($+(%,variable.,$1),2) BLAH
echo -a $eval($+(%,variable.,$1),2)

$1 could have been a %variablename also, ex %frog etc!

Joined: Mar 2003
Posts: 48
F
Ameglian cow
Offline
Ameglian cow
F
Joined: Mar 2003
Posts: 48
why so long reply's :X

%var%yourvar :

%var [ $+ [ %yourvar ] ]

works also as:

%var$nick :

%var [ $+ [ $nick ] ]

Last edited by flup; 03/07/05 08:49 AM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Becuase your asking questions about them, and sometimes a long reply is a help.

just try using [ $+ [ ] ] for this. Then you well see how sad [ ] are!

set $+(%,link.,$network,!,$nick,!,$date(yyyymmdd),!,$2) $3-

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
i will try it, but i dont think you guys understand.

I am starting out as a soft coded variable and creating a hard coded variable.

Here is what the chat would look like.

<JOE> !addme BLAH
<Bot> JOE added // /set %person. $+ $nick BLAH
<Mike> !read Bob
<Bot> Bob is not found (cant find %person.Bob)
<Mike> !read JOE
<Bot> BLAH (%person.JOE found)

$1 is a general variable, so everytime someone would use the command, they would overwrite the previous person right?
set %variable. [ $+ [ $nick ] ] BLAH
echo -a %variable. [ $+ [ $nick ] ]
will not do what I want, since it can only be used once ($nick)
I want to transform that $nick into the value of $nick so another person can use it, and start their own variable

%person. [ $+ [ $nick ] ] will take the $nick of the person who just spoke, not hard coded.

Lets say the whole chat room used the SAME script.
%person. $+ $nick (or however it works)

I would have a long variable list like:

%person.Bob
%person.Joe
%person.Mike
%person.Fred
etc...
All of which are created from the general /set %person. $+ $nick
These variable arn't temporary, only the definitions are.

Get it? :S

BTW, when I use %person. $+ $nick, i am refering to the correct way to write it incase thats not what it is.

Last edited by BNX; 03/07/05 10:20 AM.
Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
hmm, try this

Code:
on *:TEXT:!addme ?*:#: {
  set $+(%,person.,$nick) $2-
  msg $chan $nick added $+(",$2-,")
}

On *:TEXT:!read &amp;:#: {
  if ( $($+(%,person.,$2),2) ) msg $chan $v1 ( $+ $+(%,person.,$2) Found $+ )
  else msg $chan $2 does not exists ( $+ Can't find $+(%,person.,$2) $+ )
}  


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Or this, adjusted from xDaeMon's code a little to make your wording exact.

on *:TEXT:!addme *:#: {
set $+(%,person.,$nick) $2-
msg $chan $nick added // /set $+(%,person.,$nick) $2-
}
On *:TEXT:!read &:#: {
if ($var($+(%,person.,$2),1) == $+(%,person.,$2)) { msg $chan $($v2,2) ( $+ $v2 found) }
else { msg $chan $2 is not found (can't find $v2 $+ ) }
}

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
I appreciate all the help guys, but your going to kill me when you find out how easy this was.


on 51:TEXT:!add:#: {
/msg # $nick set
/set %name.of.user. $+ $nick 1
}

on 51:TEXT:!read *:#: {
if (%name.of.user. $+ $2 == 1) {
/msg # Found!
}
else {
/msg # user not found.
}
}

Logs:
<~Black_Ninja> !add
<+Wormbot> Black_Ninja set
<~Black_Ninja> !read Black_Ninja
<+Wormbot> Found!

It has successfully saved a variable named
%name.of.user.Black_Ninja

Sorry you guys had to go through a large coding tutorial, but this seemed to work after a few minutes of playing around

The reason I didn't think this would work is because normally when you define a variable, whatever the next word is after the variable is what is saved. So I figured
%name.of.user.
would have a value of
$+ Black_Ninja
But it DID parse the $+ which I was surprised to see.

Last edited by BNX; 03/07/05 09:57 PM.
Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
Your code is almost the same as to my code & Davec's. The only difference is that you could add a data when the person is added. (!addme blahblah)


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Also his code is different in the fact it doesnt work LOL!

on 51:TEXT:!read *:#: {
if (%name.of.user. $+ $2 == 1) {

^ thats not gonna work

!read bob
if (%name.of.user. $+ $2 == 1) {
if ($null $+ bob == 1) {
if (bob == 1) {

Oh well you just cant teach some people i guess smile)))

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
if (%name.of.user. $+ $2 == 1) {

does work, else I wouldnt of posted that it worked.

True if $name.of.user.$2 exists, because it will have value of 1
False if the value is not 1, because it does not exist.
I tried it, and it does work.

<person> !read bob
if (%name.of.user. $+ $2 == 1) AKA if (%name.of.user.bob == 1)

Last edited by BNX; 04/07/05 01:33 AM.
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Have you actually tested it?
<HGDSGU> !add
<Collective> HGDSGU set
<HGDSGU> !read HGDSGU
<Collective> user not found.


Let's say that "%name.of.user." was equal to "moo" (i.e. /set %name.of.user. moo)
if (%name.of.user. $+ $2 == 1) is not if (%name.of.user.bob == 1)
if (%name.of.user. $+ $2 == 1) is if (moobob == 1)

Your code is wrong, DaveC is correct.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
shall we run a little test

Code:
alias test {
  echo -
  if ((!$2) || ($2 == 1)) { echo  No second value passed test aborted! | return }
  ;
  set %name.of.user. $+ $2 1
  ;
  if (%name.of.user. $+ $2 == 1) { echo OH MY I WAS WRONG AND BNX WAS CORRECT! }
  else                           { echo OH MY I WAS RIGHT AND BNX WAS WRONG! Becuase it was testing if ( $+ $v1 == $v2 $+ ) }
  ;
  ;
  if (%name.of.user. [ $+ [ $2 ] ] == 1)     { echo Oh this method works! $replace(if_(%name.of.user._[_$+_[_$2_]_]_==_1),_,$chr(32)) }
  if ($eval($+(%,name.of.user.,$2,),2) == 1) { echo and this method! $replace(if_($eval($+(%,name.of.user.,$2,),2)_==_1),_,$chr(32)) }
  if ($($+(%,name.of.user.,$2,),2) == 1)     { echo and also even this method! $replace(if_($($+(%,name.of.user.,$2,),2)_==_1),_,$chr(32)) }
}


/test ! bob

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
[edit]

Ok, i get what you guys are saying. However, DaveC your script didn't do what I was asking, but it works.
My if statement was flawed, but I assigned the name of the variable to a temporary variable and put it in the if.

My script was simple but broken.
DaveC's script was too complex but worked.
His script made things more complicated then they had to be.

HIS
on *:TEXT:!addme *:#: {
/set $+(%,person.,$nick) $2-
/msg $chan $nick added
}
on *:TEXT:!read &:#: {
if ($var($+(%,person.,$2),1) == $+(%,person.,$2)) {
/msg $chan $($v2,2) ( $+ $v2 found) }
else {
/msg $chan $2 is not found (can't find $v2 $+ )
}
}

MINE
on *:TEXT:!add:#: {
/set $+(%,person.,$nick) 1
/msg $chan $nick added
}
on *:TEXT:!read *:#: {
/set %persontemp %person. $+ $2
if ($var(%persontemp) == 1) {
/msg $chan $2 Found!
}
else {
/msg $chan user not found
}
/unset %persontemp
}


/msg $chan $($v2,2) ( $+ $v2 found) <---- You dont need all that
/msg $chan $2 Found! <----- Works just fine


btw, why do you guys jumble your scripts together like that? Does it make your scripts look more complicated so people think your smarter? In my opinion, its much easier to script and understand when things are properly spaced and organized.

Last edited by BNX; 05/07/05 02:09 AM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
OK lets do a little bit of looking up the screen.

BNX said
Quote:
Here is what the chat would look like.
<JOE> !addme BLAH
<Bot> JOE added // /set %person. $+ $nick BLAH
<Mike> !read Bob
<Bot> Bob is not found (cant find %person.Bob)
<Mike> !read JOE
<Bot> BLAH (%person.JOE found)


here is what i said to use

Quote:
Code:
on *:TEXT:!addme *:#: {
  set $+(%,person.,$nick) $2-
  msg $chan $nick added [color:blue]// /set $+(%,person.,$nick) $2-[/color]
}
On *:TEXT:!read &amp;:#: {
  if ($var($+(%,person.,$2),1) == $+(%,person.,$2)) { msg $chan  [color:orange]$($v2,2) ( $+ $v2 found)[/color] }
  else { msg $chan $2 is not found (can't find $v2 $+ ) }
}

You well note the sections in color which attempt to comply with what you said the bot was to do.

Here is what you said my code was, its close enough, but you respaced it and added unneeded /'s and removed the blue code (although looking closely at mine i think it might have been missing a bit anyway)
Also note the green } being left on that line well force the line too line up under the IF above it, not indented as shown.

Quote:
HIS (code)
Code:
on *:TEXT:!addme *:#: {
   /set $+(%,person.,$nick) $2-
   /msg $chan $nick added 
}
on *:TEXT:!read &amp;:#: {
   if ($var($+(%,person.,$2),1) == $+(%,person.,$2)) { 
       /msg $chan $($v2,2) ( $+ $v2 found) [color:green]}[/color] 
   else { 
      /msg $chan $2 is not found (can't find $v2 $+ ) 
   }
}


now your code, which by the way AGAIN is faulty

Quote:
Code:
MINE
on *:TEXT:!add:#: {
  /set $+(%,person.,$nick) 1
  /msg $chan $nick added
}
on *:TEXT:!read *:#: {
  /set %persontemp %person. $+ $2
  if ($var(%persontemp) == 1) { 
    /msg $chan $2 Found!
  }
  else {
    /msg $chan user not found
  }
  /unset %persontemp
}


/set %persontemp %person. $+ $2
if ($var(%persontemp) == 1) {

^^^^ thats always gonna be true since you just made that vairable on the line above $var(%persontemp) is the same as $var(%persontemp,0) which tells you how many variables with the name %persontemp there are, and WOW there is 1 since you just made it above!
%persontemp s not evaluated inside ot the $var( ) this is a special condition of this identifier since it is variable names specificly that it is designed to look up.
$var($(%persontemp,2)) would be the correct method there as you need to force the evaluation of the variable to get its contents.

Quote:
/msg $chan $($v2,2) ( $+ $v2 found) <---- You dont need all that
/msg $chan $2 Found! <----- Works just fine

I direct you to the orange section above for what you specificed, the bot was to do.
Why but why if you said "!READ BOB" would you only want to reply "BOB Found"

Quote:
btw, why do you guys jumble your scripts together like that? Does it make your scripts look more complicated so people think your smarter? In my opinion, its much easier to script and understand when things are properly spaced and organized.


I well space out stuff when i feel its needed, and when its only one command in a IF ELSE i well put them following the IF or ELSE simple to align the condition and the action together.
To make people think im smarter? Did you get upset with my example script? Smarts is in the ability of code to complete the task requested.
Your intitled to your opinion, and its a fair one, if im involved in a large coding project, ill organize and setout according to the layout secifications of the project, here its just how I code at that moment, nothing more or less.


Link Copied to Clipboard