Property is not being modified

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Hugar
Kobold
Posts: 7
Joined: Wed May 23, 2012 9:10 am

Property is not being modified

Post by Hugar »

This is a huge macro, so I am going to paste a piece of it.

Code: Select all

[origem=getSelected()]
[switchToken(origem)]

[input("nome|0|Nome da Arma","tipo|Combate Desarmado,Faca,Punhal,Cajado,Porrete,Gladio,Espada,Cimitarra,Machado,Machadinha,Machado Crescente,Clava,Maca,Martelo de Guerra,Mangual Leve,Arco Simples,Arco Composto,Arco de Guerra,Lanca Leve,Lanca de Guarda,Lanca Pesada,Espada de Mao-e-Meia,Montante,Machado de Guerra,Axa de Armas,Maca de Armas,Mangual,Marreta de Guerra,Lanca de Justa,Lanca de Cavalaria|Tipo de Arma|LIST|SELECT=0 VALUE=STRING","mag|0|Bonus Magico","n|1|Numero")]

[foreach(prop,GruposArmas,"",";"): eval(prop)]

[switch(tipo),code:
case "Combate Desarmado":{
[gr=CD]
[l=0+gr+mag]
[m=-3+gr+mag]
[p=-6+gr+mag]
[db=1+mag+Forca]
[comp="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db]
[if(n=="1"):Arma1=comp]
[if(n=="2"):Arma2=comp]
[if(n=="3"):Arma3=comp]
[if(n=="4"):Arma4=comp]
};
case "Faca":{
[gr=Cl]
[l=2+gr+mag]
[m=-3+gr+mag]
[p=-5+gr+mag]
[db=2+mag+Forca]
[comp="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db]
[if(n=="1"):Arma1=comp]
[if(n=="2"):Arma2=comp]
[if(n=="3"):Arma3=comp]
[if(n=="4"):Arma4=comp]
};
case "Punhal":{
[gr=Cl]
[l=2+gr+mag]
[m=-2+gr+mag]
[p=-5+gr+mag]
[db=3+mag+Forca]
[comp="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db]
[if(n=="1"):Arma1=comp]
[if(n=="2"):Arma2=comp]
[if(n=="3"):Arma3=comp]
[if(n=="4"):Arma4=comp]
};
...
}]


Basicaly, this macro is called from a Campaign Macro. it can't be edited by players. An input asks for a name, a weapon type, a magic bonus e a number. So it will switch between the avaliable types of weapons, do some calculations e modify the original value of the Token Property Arma#.

Everything works perfectly, and no errors occours. But the Token Property Arma# is not being modified.

Any helps?

User avatar
wolph42
Deity
Posts: 9804
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Property is not being modified

Post by wolph42 »

Are the arma# properties hidden?

Edit: ah wait I think I see it. You do a comparison n=="1" while n is a number not a string, so it will always return false!
Try n==1

By the way, the code from
comp=
if(
If(
Etc.
onwards, seems to be identical for all switches, if that also the case for the switches you're not showing then you can remove them from the switch and put it 1 time after the switch is finished. You only need to put the unique code in the switch.

Hugar
Kobold
Posts: 7
Joined: Wed May 23, 2012 9:10 am

Re: Property is not being modified

Post by Hugar »

I tried to put if(n==1) and (n=="1") and it did not work. The variable n is obtained from the input on the top, and its type is string.

EDIT: I moved the comp and ifs to the bottom, outside the switch.

Hugar
Kobold
Posts: 7
Joined: Wed May 23, 2012 9:10 am

Re: Property is not being modified

Post by Hugar »

I modified the code, let me paste it here.

Code: Select all

[origem=getSelected()]
[switchToken(origem)]

[input("nome|0|Nome da Arma","tipo|Combate Desarmado,Faca,Punhal,Cajado,Porrete,Gladio,Espada,Cimitarra,Machado,Machadinha,Machado Crescente,Clava,Maca,Martelo de Guerra,Mangual Leve,Arco Simples,Arco Composto,Arco de Guerra,Lanca Leve,Lanca de Guarda,Lanca Pesada,Espada de Mao-e-Meia,Montante,Machado de Guerra,Axa de Armas,Maca de Armas,Mangual,Marreta de Guerra,Lanca de Justa,Lanca de Cavalaria|Tipo de Arma|LIST|SELECT=0 VALUE=STRING","mag|0|Bonus Magico","n|1|Numero")]

[foreach(prop,GruposArmas,"",";"): eval(prop)]

[switch(tipo),code:
case "Combate Desarmado":{
[gr=CD]
[l=0+gr+mag]
[m=-3+gr+mag]
[p=-6+gr+mag]
[db=1+mag+Forca]
};
case "Faca":{
[gr=Cl]
[l=2+gr+mag]
[m=-3+gr+mag]
[p=-5+gr+mag]
[db=2+mag+Forca]
};
...
case "Lanca de Cavalaria":{
[gr=Pp]
[l=2+gr+mag]
[m=3+gr+mag]
[p=5+gr+mag]
[db=6+mag+Forca]
}]

[switch(n):
case "1":Arma1="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "2":Arma2="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "3":Arma3="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "4":Arma4="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db]


The Token Property Arma# is not being modified! I tried putting a macro.return=comp("Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db) and it return no value!

I tried to modify the Arma# property on a blank campaign macro and it worked. Why this macro can't modify the property? It is in a LibToken. Does this make some diference? The apply to selected tokens box is checked.

I think I found some kind of bug.

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Property is not being modified

Post by Bone White »

[spoiler=Incorrect information]Your syntax for performing multiple commands with [wroll]switch[/wroll] and [wroll]code[/wroll] in the last part of your second post is wrong. The following is the correct way to do this:

Code: Select all

[h, switch(n), code :
case "1": {[function1()][function2()]};
case "2": {[function3()][function4()]};
default:
 {[function5()][function6()]}  
[/spoiler]
Last edited by Bone White on Mon May 28, 2012 8:14 am, edited 1 time in total.

User avatar
wolph42
Deity
Posts: 9804
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Property is not being modified

Post by wolph42 »

@bonewhite: there's only one command in that switch, so the syntax is correct.
The Token Property Arma# is not being modified! I tried putting a macro.return=comp("Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db) and it return no value!

Then thats you're issue, if somethings wrong with that then the var you're assigning it to won't be changed.
Try using the pause function ( search the forum for debug pause)

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Property is not being modified

Post by Bone White »

wolph, I never knew that. I'm always obsessive with using as much syntax as possible, so that may be why I didn't know this.

pause() is what wolph is on about

User avatar
wolph42
Deity
Posts: 9804
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Property is not being modified

Post by wolph42 »

@bonewhite: funny, you're becoming a well versed mt coder pretty fast, so the assumption arises that you know the 'basic' stuff... But then there isn't anything really basic about this script, which boils down to the fact that I keep learning stuff from anyone because of either a different approach or my own assumptions, similar as to this one of you.

Thnx for the link, I'm doing most of this tyPing on an iPhone, which makes creating links a... erm (can't find the word)

User avatar
patoace
Dragon
Posts: 313
Joined: Mon Sep 24, 2007 6:10 pm
Location: Rancagua - Chile

Re: Property is not being modified

Post by patoace »

This is pretty basic, but I overlooked once or twice: don't put two tokens in the same map with the same name, the macro may be changing that other token properties.

User avatar
aliasmask
Deity
Posts: 8624
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Property is not being modified

Post by aliasmask »

Hugar wrote:I modified the code, let me paste it here.

Code: Select all

[origem=getSelected()]
[switchToken(origem)]

[input("nome|0|Nome da Arma","tipo|Combate Desarmado,Faca,Punhal,Cajado,Porrete,Gladio,Espada,Cimitarra,Machado,Machadinha,Machado Crescente,Clava,Maca,Martelo de Guerra,Mangual Leve,Arco Simples,Arco Composto,Arco de Guerra,Lanca Leve,Lanca de Guarda,Lanca Pesada,Espada de Mao-e-Meia,Montante,Machado de Guerra,Axa de Armas,Maca de Armas,Mangual,Marreta de Guerra,Lanca de Justa,Lanca de Cavalaria|Tipo de Arma|LIST|SELECT=0 VALUE=STRING","mag|0|Bonus Magico","n|1|Numero")]

[foreach(prop,GruposArmas,"",";"): eval(prop)]

[switch(tipo),code:
case "Combate Desarmado":{
[gr=CD]
[l=0+gr+mag]
[m=-3+gr+mag]
[p=-6+gr+mag]
[db=1+mag+Forca]
};
case "Faca":{
[gr=Cl]
[l=2+gr+mag]
[m=-3+gr+mag]
[p=-5+gr+mag]
[db=2+mag+Forca]
};
...
case "Lanca de Cavalaria":{
[gr=Pp]
[l=2+gr+mag]
[m=3+gr+mag]
[p=5+gr+mag]
[db=6+mag+Forca]
}]

[switch(n):
case "1":Arma1="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "2":Arma2="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "3":Arma3="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db;
case "4":Arma4="Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db]


The Token Property Arma# is not being modified! I tried putting a macro.return=comp("Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db) and it return no value!

I tried to modify the Arma# property on a blank campaign macro and it worked. Why this macro can't modify the property? It is in a LibToken. Does this make some diference? The apply to selected tokens box is checked.

I think I found some kind of bug.

Where to start? Since you have no roll option formatting in your statements I'm going to assume this is in a UDF that suppresses output otherwise your stack is in a world of hurt. Also, looking at a wall of code can be difficult without proper formatting and representative variable names. Also, it's not obvious which variables you are trying to set to a token. I highly recommend not relying on the token type to have your variable predefined for you and use getProperty and setProperty. I don't see a relation from your question and your code. Is comp a UDF that assigns Arma#? The switch above which does assign Arma#'s should assign the Arma# if those are defined in the token type. Use of that switch in that case would be better executed with a set or setProperty function.

Code: Select all

[H: set("Arma"+n,"Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db)]

User avatar
wolph42
Deity
Posts: 9804
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Property is not being modified

Post by wolph42 »

AM wrote:Is comp a UDF that assigns Arma#?

with the bold comment I think that he tried to say: [h:macro.return=comp] where comp=... but it looked like a function cause of the parenthesis.

Anyway, for once I'm not behind a mobile so I can actually have a look at your code. First a suggestion for better layout and some debug statements at the bottom. Run this (do NOT suppress the output, and see what values are given and whether errors pop up.

Code: Select all

[h:origem    = getSelected()]
[
h:switchToken(origem)]

[
h:armaList     =  "Combate Desarmado,Faca,Punhal,Cajado,Porrete,Gladio,Espada,Cimitarra,Machado,Machadinha,Machado Crescente,Clava,Maca,Martelo de Guerra,Mangual Leve,Arco Simples,Arco Composto,Arco de Guerra,Lanca Leve,Lanca de Guarda,Lanca Pesada,Espada de Mao-e-Meia,Montante,Machado de Guerra,Axa de Armas,Maca de Armas,Mangual,Marreta de Guerra,Lanca de Justa,Lanca de Cavalaria"]

[
h:input(
    "nome|0|Nome da Arma",
    "tipo|"+armaList+"|Tipo de Arma|LIST|SELECT = 0 VALUE = STRING",
    "mag|0|Bonus Magico",
    
"n|1|Numero"
)]

<!--
 some comment (like this) for this particular line would be usefull, also for yourself in a later stage -->
 [h,foreach(prop,GruposArmas,"",";"): eval(prop)]

[
h,switch(tipo),code:
    case "Combate Desarmado":{
        <!-- same here, the var CD just drops out of the sky... -->
        [gr    = CD]
        [l    = 0+gr+mag]
        [m    = -3+gr+mag]
        [p    = -6+gr+mag]
        [db    = 1+mag+Forca]
    };
    case "Faca":{
        [gr    = Cl]
        [l    = 2+gr+mag]
        [m    = -3+gr+mag]
        [p    = -5+gr+mag]
        [db    = 2+mag+Forca]
    };
    ...
    case "Lanca de Cavalaria":{
        [gr    = Pp]
        [l    = 2+gr+mag]
        [m    = 3+gr+mag]
        [p    = 5+gr+mag]
        [db    = 6+mag+Forca]
}]

<!--
 let us know what these variables say, if any is empty or pops up an input box then 'theres your problem' -->
[
gr]<br>
[
l]<br>
[
m]<br>
[
p]<br>
[
db]<br>

[
H: set("Arma"+n,"Nome="+nome+";AtqL="+l+";AtqM="+m+";AtqP="+p+";DanoB="+db)] 

Also code like:

Code: Select all

 [h,foreach(prop,GruposArmas,"",";"): eval(prop)] 
which uses variables without any reference (comment) where they come from nor doesn't really make it well for debugging

Hugar
Kobold
Posts: 7
Joined: Wed May 23, 2012 9:10 am

Re: Property is not being modified

Post by Hugar »

Well, I stayed away from internet for a few days. Thanks for everyone for the help. But I think you would be able to find the problem only if you had the cmpgn file. It's very complicated once it refeers to Token Properties unknown for you.

I am going take a break from it. Most of the code is ready and other occupations are more important right know. When I return working on it, I will appreciate sharing my work with you all.

Many thanks again!

Post Reply

Return to “Macros”