mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 43
C
Cypris Offline OP
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 43
This may sound odd...but I need my script to KNOW if a var passed to it is global (/set) or local (/var)?

I suppose i could make an alias called /set and have it write to an ini , the variable name as ITEM and Global as VALUE, but then i would need to have an alias for unset and yada yada. (the same for /var too)

But CMON! There has to be a way! $var() searches both var types,

The reason i need to do this is because i am writting an alias called VADD which adds the string/data to the end of the variable instead of overwritting it, and if i pass it a local var, i dont want to /set it, i want to /var %var = %var $+ %newdata.

Any ideas. i really hope i overlooked something and this is more simple than i think it is.


-Cypris
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias varexists { return $iif($eval($1,2) != $null,$true,$false) }


//var %x = test | echo -a $varexists(% $+ x) | set %x test | echo -a $varexists(% $+ x) | unset %x

This will not check if a local variable exists, it will return $false if the variable doesn't exist at all or is local, but I think that's the best you can do.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
cant you use /set %var %var

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
As long as it's declared first.

Code:
var %var
; %var = <value> or /set %var <value> will both set the value of the local %var

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
alias isglobal { return $iif($var($1),$true,$false) }

I think that would be better, dont malfunction if the global exists but contains $null or text litteral "$null" also doesnt care if u go $isglobal(% $+ var) or $isglobal(var) {with no %}

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Quote:
dont malfunction if the global exists but contains $null


That would have 0 uses anyway :tongue: I see what you mean about the text $null though.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
That would have 0 uses anyway :tongue: I see what you mean about the text $null though.


LOL I know it wouldnt have almost any uses, well none i could think of at least. The string litteral "$null" caught me out once and i didnt work it out for ages, i was processing a load of stuff to make a composite line, and looping till i got a blank line, not expecting "$null" on a line frown

This is interesting tho, as i think i shopuld have read what the orginal poster anted to do anyway...
Quote:
The reason i need to do this is because i am writting an alias called VADD which adds the string/data to the end of the variable instead of overwritting it, and if i pass it a local var, i dont want to /set it, i want to /var %var = %var $+ %newdata.


I assume he means hes passing the variable name to the alias, so hes passing by refrence rather than value, and if thats the fact then he cant pass a local var anyway, as it wont exist in the alias he passed it too, ie: there would be no point in doing "/var %var = %var $+ %newdata" becuase as the alias exits %var well be destroyed, not that it would have had any value before the /var that created it in the alais anyway!

why he doesnt just use %var = $+(%var,%newdata) seems a bit off to me!

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
local variables aren't carried over from alias to alias, even if one calls the other :tongue: so, if in your alias named VADD you want to modify the value of a variable that is local to the parent alias, you'll find it's not possible :s unless you return a piece of data to the parent instructing it to declare the variable locally

for example:

Code:
alias VADD {
........
 return set $(%var %var $+,) %newdata
}


then in your parent alias call $($vadd(),2) as a command

as hixxy said, /set first looks for local variables to change the value of, then moves on to global ones if none is found. this should be just what you need shocked


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Quote:

why he doesnt just use %var = $+(%var,%newdata) seems a bit off to me!


i was wondering the same lol. maybe VADD contains a lot of code, that he's calling from more than one alias :> if not, it should certainly be done away with


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
rereading the OP I should have said
/set %var %var $1
he was saying he wanted to pass the value of a local var to another alias that would add that to a global var
alias lvar {
var %one = $?
if (%one == test) { addon %one }
}
alias addon {
set %two %two $1
}

or just

alias lvar {
var %one = $?
if (%one == test) { set %two %two %one }
}

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
pardon? lol

I read that he thinks he can pass a variable by refrence rather than how mirc actually passes all info by value, he said "if a var passed to it is global (/set) or local (/var)", since the var is passed not as the var but as its contents, there is no back refrence possable. Unless of course hes passing the litteral text "%var" and then hes got the problem with it not existing as a local in the alias anyway, so could detect a global but not if it was a local in the calling alias.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
true, so I guess the only way to tell is check the var has a value before passing it $($+(%,var),0) and if it has no value after being evealuated twice in the alias then being $null it was a local var??

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Stunned noone mentioned this:
Code:
alias local { 
  var %x = 1
  set %y 1
  echo -a $var(%y,1).local $var(%x,1).local
}


$maybe
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
I can't remeber Everything! smile

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
LOL just came back to this thread to mention that, now that i finally read it in the help (/me wonders how long its been in there for since i never saw it before, likely longer than i amagine!)

I think the thread got of the first page, whcih normally ends it for me, otherwise i would have seen your reply!

Something else i saw thats nice
Code:
alias ex { 
  set %x global | var %x = local
  echo -a $var(%x,1) = $var(%x,1).value ... is it local? $var(%x,1).local
  echo -a $var(%x,2) = $var(%x,2).value ... is it local? $var(%x,2).local
}

/ex
%x = local ... is it local? $true
%x = global ... is it local? $false


Link Copied to Clipboard