Assigning value to a variable (Programming Macro Question)

Discussion about everything RO and OpenKore related. This place is NOT for ANY kind of support questions.

Moderator: Moderators

loydi12345
Noob
Noob
Posts: 11
Joined: 20 Jul 2008, 09:48
Noob?: Yes

Assigning value to a variable (Programming Macro Question)

#1 Post by loydi12345 »

My apologies if this is not posted on the right thread. Feel free to move it mod if I'm on the wrong thread.

Okay, so I have been programming lots of codes already particularly C and Basic. I haven't dissected yet the whole macro programming here. Is it possible to assign value like for example map on a variable? I am thinking about something like this.

'config is: lockmap gef_fild01

'declare variable x as global variable

Code: Select all

automacro changemap{
	timeout 600
	call {
             if (x == gef_fild01){
                  x = prt_fild01;
             }
             else {
                   x = gef_fild01;
             } 
		
		do talk @npc (88 159)        'talking at an npc
		do talk resp 1                    'choosing to add text on warper npc  
		do talk text x                     'placing variable x as the lockmap
		do conf lockmap x
		release changemap
	}
}

Code: Select all

automacro anothermacro{
              location x
              'other conditions
              call {
                    do c @return
                    release anothermacro
               }
}


Is it possible?
ever_boy_
Developers
Developers
Posts: 308
Joined: 06 Jul 2012, 13:44
Noob?: No

Re: Assigning value to a variable (Programming Macro Question)

#2 Post by ever_boy_ »

loydi12345 wrote:Is it possible to assign value like for example map on a variable?
of course you can. although I didn't fully understand what you want to do.

Code: Select all

x = $.map
or

Code: Select all

x = @config(lockMap)
but, as far as I know, macros can't handle that if statement syntax.
you should use this instead:

if (condition) goto [label]
iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG

Re: Assigning value to a variable (Programming Macro Question)

#3 Post by iMikeLance »

Just complementing what ever_boy_ said:
You should use $ before every variable name.
$var for macro variables. These will ALWAYS be global.
$.var for some special variables, like $.map, $.lastMatchN.
$::var for openkore variables used inside @eval. This is something special and very useful. Anything inside @eval is perl code. If you know how to code in perl then you can write some VERY powerful macros. You can also write perl subroutines INSIDE macros.txt file.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Assigning value to a variable (Programming Macro Question)

#4 Post by EternalHarvest »

iMikeLance wrote:$::var for openkore variables used inside @eval.
Actually, that's just a workaround for bugs in macro design/parser. $::foo in Perl is the same as $main::foo.
ever_boy_
Developers
Developers
Posts: 308
Joined: 06 Jul 2012, 13:44
Noob?: No

Re: Assigning value to a variable (Programming Macro Question)

#5 Post by ever_boy_ »

iMikeLance wrote: You can also write perl subroutines INSIDE macros.txt file.
Oh yeah, I forgot about that. So you can use perl's if statement, once it's inside a perl's sub.
loydi12345
Noob
Noob
Posts: 11
Joined: 20 Jul 2008, 09:48
Noob?: Yes

Re: Assigning value to a variable (Programming Macro Question)

#6 Post by loydi12345 »

Sorry I forgot to return and post again an update here lol. I'm glad that I got replies from different developers.

So here's so far what I did and it worked :D :D

Code: Select all

$value = prt_fild01

automacro changemap{
	timeout 1800
	exclusive 1
	call {
	     if ($value == prt_fild01) goto one
 	     if ($value == prt_fild03) goto two
	     :one
 		$value = prt_fild03
	     stop
	     :two
 		$value = prt_fild01
	     stop
	}
}
			

automacro autowarp{
	weight < 50%
	location prontera
	timeout 30
	exclusive 1
	call {
		do talk @npc (88 159)
		pause 5
		do talk resp 1
		pause 5
		do conf lockMap $value
		do talk text $value
		release autowarp
	}
}
I just wonder here though. I made a declaration outside all the macros and automacros statements and it still worked. Any explanation here? I thought the only things that will be initialized are variables inside macros and automacros statements? Also, does perl programming have an if and else statement?

I'm having a nose bleed with all those variables you have mentioned like $::var and $::foo. Well I used to copy paste way way years before but since I have experienced programming for almost 2 years I wanna give a try on how flexible I could be on developing even just some simple codes on a different programming language like Perl.

I am somehow sad though that the market is not much looking for Perl programmers. I've been looking for companies' looking for them but I can only see a few and this discourages me to learn this. What other applications do you think that uses perl aside from OK?
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Assigning value to a variable (Programming Macro Question)

#7 Post by EternalHarvest »

loydi12345 wrote:I made a declaration outside all the macros and automacros statements and it still worked. Any explanation here? I thought the only things that will be initialized are variables inside macros and automacros statements?
No idea.
loydi12345 wrote:Also, does perl programming have an if and else statement?
Sure.
loydi12345 wrote:What other applications do you think that uses perl aside from OK?
If you just want examples, wikipedia has some.
chocobrowny
Noob
Noob
Posts: 19
Joined: 21 Jul 2011, 01:16
Noob?: No

Re: Assigning value to a variable (Programming Macro Question)

#8 Post by chocobrowny »

1. Macro script help us to create bot activities easily but it's not perl.
2. Some patterns in macro.txt read like perl but some are not. (Advise to read the src of macro plugin)
3. You can open book for command or pattern of each programming language but you can't find the logical process or algorithm,
so I think not waste to learn perl programming.
4. May be help you with "location x" >> https://chocobrowny.wordpress.com/2012/09/07/227/
"...Every coin have two sides, think more widely and Not everything is black and white, there are shades of grey..."
Image