It looks like you're new here. If you want to get involved, click one of these buttons!
try {
version.extensions['BlueprintMacro'] = {
major:1, minor:0, revision:0
};
macros['Blueprint'] = {
handler: function(place, macroName, params, parser) {
new Wikifier(place, "<html>img src=Office.jpg height='337' width='640'</html>");
>
},
init: function() { },
};
} catch(e) {
throwError(place,"macrodemo Setup Error: "+e.message);
}
However what I want to do is have a macro that will look and function as little like this. So the code below is pure fiction try {
version.extensions['BlueprintMacro'] = {
major:1, minor:0, revision:0
};
macros['Blueprint'] = {
handler: function(place, macroName, params, parser) {
try
{
switch (place)
{
case "location001":
result = "<html>img src=ImageA.jpg height='337' width='640'<html>";
break;
case "location002":
result = "<html>img src=ImageB.jpg height='337' width='640'<html>";
break;
case "location003":
result = "<html>img src=ImageC.jpg height='337' width='640'<html>";
break;
}
new Wikifier(place, result);
>
},
init: function() { },
};
} catch(e) {
throwError(place,"macrodemo Setup Error: "+e.message);
}
If anyone can enlighten me how to make this work it would be much appreciated.
Comments
Put a naming convention in and you can: in your entry macro.
Thanks MadExile and myKael for your replies. MadExile when I run this i get that "missing location argument" displaying in red. Then I wondered whether i was suppose to be putting a variable into the macro like <<bluepring locationpassagename>> but this throws the unknown location error message.
If you remember my thread for my map that uses object properties (http://twinery.org/forum/index.php/topic,45.msg3537.html#msg3537), this relates to that, and i am wondering whether instead of checking the locationname and matching it, perhaps be better to use a value from $CurrentPos.LocId instead. This way i can keep reusing images to represent new locations that have the same layout, which in the long run is better than having a long list of matching passage names where a lot of double handling would occur.
So I had a go at adding the variable to the macro caller (er whatever you call that) but alas it didnt work. Error is unknown location as per error check in the script.
The macro was called with this which should hold the value "Loc020" i would of thought, that value should be correct because in my passage it meets the condition to run the macro. Discovering how to display a variable in a script as a debug check with its shows $CurrentPos.LocId as if that is the text string i am wanting to carry across. Its probably something really obvious I am not getting here. But that is part of learning i guess lol. I thought params was the value of what has been included with the macro to be passed on, which seems to be partly working i guess, except its not taking on the value inside that variable. Understanding how would be another step in understanding macros.
Here's an updated version, which takes a string (e.g. "Loc001") or a $variable: Usage:
On the other hand, if you did want to call it without arguments, then you'll need to access the location internally, like so: Usage: [EDIT] Fixed code cockup.
Its working now
the line the follows it- is that just initializing the variable 'result' on the end of that line above it- opposed to a new line with var result =""; or something? or you do not need to place an empty value into it either an integer or string?
Thanks again MadExile
To break that down a bit. First off,
?:
is the ternary (or conditional) operator, which you can think of as an inlineif
statement. It works like this: That in mind, the entire expression works like this: (RegExp object & RegExptest()
method)It declares the variable
result
, but does not initialize it to any value. In this case assigning it a value upon declaration isn't necessary as the immediately following switch statement either assigns it a value, before it's used in the followingWikifier()
call, or tosses an error and returns, bypassing theWikifier()
call.I'm trying to convert this to sugarcube, going off another script you altered for me where you changed the beginning, I also changed the state.active.variables this is what i have... I get an error Unexpected token ;
There is three open brackets so there needs to be three closing brackets right? so somewhere there is an extra ; where it should be unless it something else a miss here? maybe the parser.fullMatch() needs to be declared first?
That is from missing the closing parenthesis for
macros.add()
.There were a few other issues as well.
Try this:
Anyway thanks again. That's another script converted and working in sugarcube now.