Concatenating strings with @eval()

All about the macro plugin can be found in this forum. This forum is intended for the macro plugin only.

Moderator: Moderators

toasterAreYum
Noob
Noob
Posts: 4
Joined: 05 Jul 2011, 16:10
Noob?: No

Concatenating strings with @eval()

#1 Post by toasterAreYum »

Code: Select all

$name1 = David
$name2 = son
$playerName = @eval($name1 . $name2)
syntax error

Code: Select all

$num1 = 1
$num2 = 2
$numTotal = @eval($num1+$num2)
numTotal = 3

Code: Select all

$num1 = 1
$num2 = 2
$numTotal = @eval($num1 . $num2)
numTotal = 12

Do I have to use a sub-line?

Thanks in advance. Love you.... xoxoxo

edit: also, I can't seem to put $var into the regexp in the autoMacro.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Concatenating strings with @eval()

#2 Post by EternalHarvest »

toasterAreYum wrote:

Code: Select all

$playerName = @eval($name1 . $name2)
Macro plugin probably has bad idea about messing with Perl code first (replacing macro variables with their content), so there would be unquoted strings. Quote them or use $Macro::Data::varStack{name1} etc instead.
toasterAreYum
Noob
Noob
Posts: 4
Joined: 05 Jul 2011, 16:10
Noob?: No

Re: Concatenating strings with @eval()

#3 Post by toasterAreYum »

Beautiful, thanks very much.
I have a big project happening, so I may be asking more questions in the forum.
Obviously I'll try my hardest to learn it first.

To elaborate on my question about regexp, an example of what I'm trying to do.

Code: Select all

automacro 1 {
guild /!($myNameIs) ($command)/
call main
}
because at the moment, I can't just call my macros the command name. I have to change my macros.txt for each bot to suit the callSign that I want to use.

eg:

Code: Select all

automacro 4 {
guild /!(botName|a) (move|follow) (.*) (.*)/
call main
}
macro main{
if ($.caller == 4 && $.lastMatch == move) call move
}
macro move{
do move etc etc
conf etc etc
do g etc
}
As you can see, if there's a way to put $variables into a regexp it'll cut my code, and mean that I can have the same macros.txt for each bot.

Perhaps a subroutine somewhere.