Jump to content

Variable Problems


Marcus

Recommended Posts

I am trying to only have one coupon (resource), which can be used in 4 different positions, that uses a var1 that has different values depending on which text box is to be used. I am a not very experienced with Java, but here is what I have so far. I feel like I need some sort of way to determine which text box is to be used.

 

if (Field("COUPON_COD") == "C1")

{

return("MyVar1", Field("N_VAR_1"));

}

if (Field("COUPON_CO2") == "C1")

{

return("MyVar1", Field("N_VAR_1__2"));

}

 

if (Field("COUPON_CO3") == "C1")

{

return("MyVar1", Field("N_VAR_1__3"));

}

if (Field("COUPON_CO4") == "C1")

{

return("MyVar1", Field("N_VAR_1__4"));

}

 

Thanks,

 

Marcus

Link to comment
Share on other sites

Help! I have a coupon resource that I need to change values depending on which text box is active. I wanted to have all text boxes using the same resource but changing the value of <<MyVar1>> with a rule that works by the flow of the text boxes, which I can seem to figure out. Any suggestions?

Link to comment
Share on other sites

I don't understand what you're trying to do. Can you post an example?

 

Are you trying to a return a specific value for a variable, "MyVar1", depending on which coupon field's value is "C1"? If so, your current code could just be modified to look like this:

if (Field("COUPON_COD") == "C1")
{
 return Field("N_VAR_1");
}
if (Field("COUPON_CO2") == "C1")
{
 return Field("N_VAR_1__2");
}
if (Field("COUPON_CO3") == "C1")
{
 return Field("N_VAR_1__3");
}
if (Field("COUPON_CO4") == "C1")
{
 return Field("N_VAR_1__4");
}

 

Or:

var i = 5;
while (--i > 2)
 if (Field("COUPON_CO" + i) == 'C1')
   return Field("N_VAR_1__" + i);
return (Field("COUPON_COD") == "C1") ? Field("N_VAR_1") : '';

 

Assuming you've named your text frames, you can see a text frame's name by checking the "Re-evaluate this rule for every text flow" and entering this rule:

return FusionPro.Composition.CurrentFlow.name;

Link to comment
Share on other sites

This was the code that I ended up with.

  
var r = [
[Field("N_VAR_1")],[Field("N_VAR_1__2")],[Field("N_VAR_1__3")],[Field("N_VAR_1__4")]
];
var x = FusionPro.Composition.CurrentFlow.name
return r[x];

 

That works for you? As I said before, I (still) don't really understand what you're trying to do and while I'm happy if that code does what you're trying to do, I just don't understand it.

 

You've made an array named 'r'. Within 'r' you've put 4 fields, each within their own array. So assuming you've named your frames 0,1,2, and 3, I still don't understand how that could return a unique value for each frame. If your ultimate goal is to return Field("N_VAR_1") in frame "0", Field("N_VAR_1__2") in frame "1" and so forth, you'd need to modify your code to be:

var r = [
[Field("N_VAR_1")],[Field("N_VAR_1__2")],[Field("N_VAR_1__3")],[Field("N_VAR_1__4")]
];
var x = FusionPro.Composition.CurrentFlow.name
return r[color="Red"][0][/color][x];

Or just get rid of the 2D array:

return [
 Field("N_VAR_1"), 
 Field("N_VAR_1__2"), 
 Field("N_VAR_1__3"), 
 Field("N_VAR_1__4")
][FusionPro.Composition.CurrentFlow.name];

Link to comment
Share on other sites

I am using a flat data file that has four coupons in it. Each coupon has different value(s) for their start dates... and other jobs could have different coupons in each position.

 

I just thought it would be easier to try and figure this out with just the values and then use it with everything else. I wanted code that would allow me to use only one resource which could be used in any position and pull the corresponding values from the file depending upon that position.

 

I like the later code you posted, it works for me. Excuse my code, I am very unfamiliar with JavaScript, but trying to learn it. Any suggestions for rapid learning JavaScrpit code for FusionPro?

 

Thank you for your help!

Link to comment
Share on other sites

Excuse my code, I am very unfamiliar with JavaScript, but trying to learn it. Any suggestions for rapid learning JavaScrpit code for FusionPro?

No worries! I just wanted to make sure you were able to accomplish what you were trying to do. If you discover a way to rapidly learn JavaScript, please share haha. My recommendation is simply to participate in this forum. Ask questions and ask for clarification if you don't understand a solution. Of course there are video tutorials as well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...