how to use regexp with variable?

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

Moderator: Moderators

ba573318
Noob
Noob
Posts: 4
Joined: 09 Apr 2014, 07:51
Noob?: Yes

how to use regexp with variable?

#1 Post by ba573318 »

like this:

$variable = abc

Code: Select all

automacro auto {
    console /^hello $variable$/  # I know it's worng
    ...
    ...
}
My goal is to catch the "hello abc" string

Can anyone help me? Thanks! :)
User avatar
4epT
Developers
Developers
Posts: 627
Joined: 30 Apr 2008, 14:17
Noob?: No
Discord: ya4ept#8494
Location: Moskow (Russia)

Re: how to use regexp with variable?

#2 Post by 4epT »

Why do you need?
All my posts are made by machine translator!
¤ Manual ¤ Anti BotKiller ¤ Packet Extractor v3 ¤
Image
Image
ba573318
Noob
Noob
Posts: 4
Joined: 09 Apr 2014, 07:51
Noob?: Yes

Re: how to use regexp with variable?

#3 Post by ba573318 »

I am very new to perl and macro

I want to use a macro to initialize all the variable i need to use

and use these variable to catch event

need some advice

Thanks a lot :P
User avatar
4epT
Developers
Developers
Posts: 627
Joined: 30 Apr 2008, 14:17
Noob?: No
Discord: ya4ept#8494
Location: Moskow (Russia)

Re: how to use regexp with variable?

#4 Post by 4epT »

describe the situation in more detail
All my posts are made by machine translator!
¤ Manual ¤ Anti BotKiller ¤ Packet Extractor v3 ¤
Image
Image
ba573318
Noob
Noob
Posts: 4
Joined: 09 Apr 2014, 07:51
Noob?: Yes

Re: how to use regexp with variable?

#5 Post by ba573318 »

I have more than 3 bot

They will trigger by other people public chat with content like "hello aaa", "hello bbb", "hello ccc".

I don't want to use /^hello (.*)$/ to trigger event because I don't want to let

these bots can be triggered simultaneously and independently by one people.

BOT A trigger by /^hello aaa$/

BOT B trigger by /^hello bbb$/

BOT C trigger by /^hello ccc$/

So that, three players can public chat to trigger these three bots simultaneously.

The aaa bbb ccc also use in current trigger macro and other macro,

so I want to use a macro to initialize all the variable I need.

Then, I can copy past the macros.txt to other bot and only change the initialize macro.

This is why I ask this question. :)

sorry for my bad english :oops:
User avatar
4epT
Developers
Developers
Posts: 627
Joined: 30 Apr 2008, 14:17
Noob?: No
Discord: ya4ept#8494
Location: Moskow (Russia)

Re: how to use regexp with variable?

#6 Post by 4epT »

Code: Select all

automacro start {
	console /^hello (.*)$/
	call {
		do c hi
		$x = $.lastMatch1
		do c var = $x
	}
}

automacro bot1 {
	var x = aaa
	timeout 5
	call {
		do c I'm bot aaa
	}
}
automacro bot2 {
	var x = bbb
	timeout 5
	call {
		do c I'm bot bbb
	}
}
All my posts are made by machine translator!
¤ Manual ¤ Anti BotKiller ¤ Packet Extractor v3 ¤
Image
Image
ba573318
Noob
Noob
Posts: 4
Joined: 09 Apr 2014, 07:51
Noob?: Yes

Re: how to use regexp with variable?

#7 Post by ba573318 »

Thanks for your help! :D