Okxa 1 Posted October 13, 2016 I am trying to show how much it takes to elite a tank as a progress bar. However, because it's not a percentage the bar is almost (when xpleft<width of the cell) always too long: Is there a way to convert it to a ratio? My code: // XP to Elite // Progress Bar { "x": 4, "y": 78, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "width": "{{v.xpToEliteLeft}}", "height": 2, "bgColor": "{{v.c_damageRating}}" }, //Text { "x": 0, "y": 28, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "alpha": "{{v.xpToEliteLeft?100|0}}", "format": "<font size='10' color='#D4D4D4'>XP to Elite:" }, { "x": 1, "y": 40, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "format": "<font size='10' color='{{v.c_battles}}'><font face='Arial'>{{v.xpToEliteLeft}}</font>" }, Also is there a way to colorize it by the amount of xp left? I tried to make a custom color macro but I couldn't get it to work. Quote Share this post Link to post Short link Share on other sites
konrad509 445 #359024 Posted October 13, 2016 { "x": 4, "y": 78, "layer": "top", "alpha": "{{v.xpToEliteLeft?100|0}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}},{{v.xpToEliteLeft}})}},{{v.xpToElite}})}},160)}}", "height": 2, "bgColor": "{{v.c_damageRating}}" }, math.zip 1 Quote Share this post Link to post Short link Share on other sites
Okxa 1 #359127 Posted October 14, 2016 (edited) What's wrong? I get the following in XVM log: 2016-10-14 13:58:51: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 49, in literal_eval File "scripts/common/Lib/ast.py", line 37, in parse File "<unknown>", line 1 (,) ^ SyntaxError: invalid syntax arg='math.sub(,)' 2016-10-14 13:58:51: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 80, in literal_eval File "scripts/common/Lib/ast.py", line 58, in _convert File "scripts/common/Lib/ast.py", line 79, in _convert ValueError: malformed string arg='math.div(null,)' 2016-10-14 13:58:51: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 80, in literal_eval File "scripts/common/Lib/ast.py", line 58, in _convert File "scripts/common/Lib/ast.py", line 79, in _convert ValueError: malformed string arg='math.mul(null,160)' 2016-10-14 13:58:52: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 155, in process_python_macro File "xvm_main/python_macro.py", line 148, in <lambda> TypeError: math_sub() takes exactly 2 arguments (1 given) arg='math.sub(440,)' 2016-10-14 13:58:52: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.p Is it because?: TypeError: math_sub() takes exactly 2 arguments (1 given) Even though it should have 2 arguments. Or do I have files required? Is the math.py required in somewhere specific place or is the one in "res_mods\configs\xvm\py_macro" enough? EDIT: Or is the reason that it requires other than 0 (as elited tanks have 0 xp required)? By doing this the bars show up (incorrectly so I get still errors). "width": "{{v.xpToEliteLeft}}?{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}},{{v.xpToEliteLeft}})}},{{v.xpToElite}})}},160)}|0}", But I still get this in XVM.log: 2016-10-14 14:21:01: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 49, in literal_eval File "scripts/common/Lib/ast.py", line 37, in parse File "<unknown>", line 1 (,) ^ SyntaxError: invalid syntax arg='math.sub(,)' 2016-10-14 14:21:01: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 80, in literal_eval File "scripts/common/Lib/ast.py", line 58, in _convert File "scripts/common/Lib/ast.py", line 79, in _convert ValueError: malformed string arg='math.div(null,)' 2016-10-14 14:21:01: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 155, in process_python_macro File "xvm_main/python_macro.py", line 148, in <lambda> TypeError: math_sub() takes exactly 2 arguments (1 given) arg='math.sub(440,)' 2016-10-14 14:21:01: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 154, in process_python_macro File "xvm_main/python_macro.py", line 142, in get_function File "scripts/common/Lib/ast.py", line 80, in literal_eval File "scripts/common/Lib/ast.py", line 58, in _convert File "scripts/common/Lib/ast.py", line 79, in _convert ValueError: malformed string arg='math.div(null,440)' Edited October 14, 2016 by Okxa Quote Share this post Link to post Short link Share on other sites
konrad509 445 #359332 Posted October 14, 2016 (edited) But do you see any bars? Do they vary in length depending on remaining XP to elite? Or doesn't it work for you at all? I didn't check the log, because it worked for me, though there are indeed some errors. But if it works, why bother with errors? ;) Edited October 14, 2016 by konrad509 Quote Share this post Link to post Short link Share on other sites
Okxa 1 #359409 Posted October 15, 2016 With your code, no I dont see any bars.However, when I manually set alpha to 100, there are bars on elited tanks Theres something strange going on with python? but what? Quote Share this post Link to post Short link Share on other sites
konrad509 445 #359433 Posted October 15, 2016 This is how it looks for me But yeah, with alpha set to 100, the bars are displayed for elited tanks. Although not for all. Quote Share this post Link to post Short link Share on other sites
Okxa 1 #360734 Posted October 20, 2016 Do you have any errors about this in XVM.log? If not then I have something wrong with my xvm? Also what xvm version are you on? I couldn't get this to work on the latest release build XVM 6.4.6.2 (6577) I got the errors mentioned earlier to my XVM.log. Quote Share this post Link to post Short link Share on other sites
konrad509 445 #360739 Posted October 20, 2016 Yes, I have errors too (as I already mentioned earlier). And I'm also using 6.4.6.2. Quote Share this post Link to post Short link Share on other sites
huepper 1 #362257 Posted October 25, 2016 (edited) The calculation of the length of the progress bar isn't easy ... :/ I think the calculation must be this way: 160 * (100 - (100 * v.xpToEliteLeft / v.xpToElite)) / 100 = width Who will integrate this in a script file? :) EDIT: This will not work: "width": "{{py.math.div({{py.math.sub(100,{{py.math.div(100,{{py.math.div({{py.math.mul({{v.xpToEliteLeft}},{{v.ToElite}})}})}})}})}})}}", But i am not a programmer. Edited October 25, 2016 by huepper Quote Share this post Link to post Short link Share on other sites
huepper 1 #362345 Posted October 26, 2016 Hello, it works like konrad509 said, this is what i have now. // XP to Elite // Progress Bar { "x": 2, "y": 97, "layer": "top", "alpha": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 100)}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" }, //Text { "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" , "shadow": ${ "def.textFieldShadow" } }, { "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" , "shadow": ${ "def.textFieldShadow" } }, As you see, i use the same line for alpha, but with 100 at the end of line. Quote Share this post Link to post Short link Share on other sites
Szulson 15 #362376 Posted October 26, 2016 Hello, it works like konrad509 said, this is what i have now. // XP to Elite // Progress Bar { "x": 2, "y": 97, "layer": "top", "alpha": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 100)}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" }, //Text { "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" , "shadow": ${ "def.textFieldShadow" } }, { "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "100", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" , "shadow": ${ "def.textFieldShadow" } }, As you see, i use the same line for alpha, but with 100 at the end of line. alpha.jpg Try to change alpha:100 for this: "alpha" : "{{v.elite?0|100}}", It will show You Text, Only on Not Elite Tank Quote Share this post Link to post Short link Share on other sites
huepper 1 #362410 Posted October 26, 2016 Try to change alpha:100 for this: "alpha" : "{{v.elite?0|100}}", It will show You Text, Only on Not Elite Tank Thanks, this works perfect. :) // XP to Elite // Progress Bar { "x": 2, "y": 97, "layer": "top", "alpha": "{{v.elite?0|100}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 160)}}", "height": 2, "bgColor": "#FF6600" }, //Text { "x": 80, "y": 2, "align": "center", "layer": "top", "alpha": "{{v.elite?0|100}}", "format": "<b><font size='11' color='#D4D4D4' face='$FieldFont'>XP to Elite:</font></b>" , "shadow": ${ "def.textFieldShadow" } }, { "x": 80, "y": 14, "align": "center", "layer": "top", "alpha": "{{v.elite?0|100}}", "format": "<b><font size='11' color='#FF6600' face='$FieldFont'>{{v.xpToEliteLeft}} / {{v.xpToElite}}</font></b>" , "shadow": ${ "def.textFieldShadow" } }, Quote Share this post Link to post Short link Share on other sites
enigma66 4 #362429 Posted October 26, 2016 Hello,sorry ny english, I would like to add this thing, But I am ignorant on the subject. I tried to copy / paste at the end of strings carousel.xc, but it does not work and it is I who am wrong. Where they copy these strings, in what position? thank you so much for what you do. Quote Share this post Link to post Short link Share on other sites
Okxa 1 #362573 Posted October 27, 2016 So I cant get it to work... I even updated to the latest xvm (XVM-6.4.7.1)Code, alpha is always 100 for testing purposes: // XP to Elite { "x": 2, "y": 79, "layer": "top", "alpha": "{{v.elite?100|100}}", "width": "{{py:math.mul({{py:math.div({{py:math.sub({{v.xpToElite}}, {{v.xpToEliteLeft}})}}, {{v.xpToElite}})}}, 126)}}", "height": 2, "bgColor": "#FF6600" }, Here's what it still looks like: I still get the same errors to my XVM.log, whats wrong? 2016-10-27 13:36:42: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 156, in process_python_macro File "xvm_main/python_macro.py", line 144, in get_function File "scripts/common/Lib/ast.py", line 49, in literal_eval File "scripts/common/Lib/ast.py", line 37, in parse File "<unknown>", line 1 (, ) ^ SyntaxError: invalid syntax arg='math.sub(, )' 2016-10-27 13:36:42: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 156, in process_python_macro File "xvm_main/python_macro.py", line 144, in get_function File "scripts/common/Lib/ast.py", line 49, in literal_eval File "scripts/common/Lib/ast.py", line 37, in parse File "<unknown>", line 1 (, ) ^ SyntaxError: invalid syntax arg='math.div(, )' 2016-10-27 13:36:42: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 156, in process_python_macro File "xvm_main/python_macro.py", line 144, in get_function File "scripts/common/Lib/ast.py", line 49, in literal_eval File "scripts/common/Lib/ast.py", line 37, in parse File "<unknown>", line 1 (, 126) ^ SyntaxError: invalid syntax arg='math.mul(, 126)' 2016-10-27 13:36:43: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 157, in process_python_macro File "xvm_main/python_macro.py", line 150, in <lambda> TypeError: math_sub() takes exactly 2 arguments (1 given) arg='math.sub(440, )' 2016-10-27 13:36:43: [ERROR] Traceback (most recent call last): File "xvm_main/python_macro.py", line 156, in pr There are also my full XVM.log and my carousel config file attached, if that would help you. Or could you test it with my carousel file? XVM.log carouselNormal.xc Quote Share this post Link to post Short link Share on other sites
konrad509 445 #362587 Posted October 27, 2016 (edited) Did you replace the original file math.py with the one from the archive I attached? I forgot that each time you update XVM, the folder py_macro is overwritten, so you lose any changes made to the files in it. My knowledge about Python is very, very basic, but I think this modified function can moved to a different file, so you don't need to worry about overwriting it while updating XVM. ^ (This sentence is still true ) Yes, it can be done. Unpack it into py_macro folder and in the config change py:math.div to py:fdiv.div. fdiv.zip Here's ready file carouselNormal.xc Edited October 27, 2016 by konrad509 Quote Share this post Link to post Short link Share on other sites
Okxa 1 #362782 Posted October 28, 2016 Oh I didn't realize that you had modified a function, so I just though the math.py you provided wasn't required.... Now it's working perfect. Quote Share this post Link to post Short link Share on other sites
skitey 0 #474564 Posted January 2, 2020 really nice thx for this code snipped. i found i bug/problem and hope it could be fixed... the blueprints are not included in this calculation..my 7% less exp isn't added. Quote Share this post Link to post Short link Share on other sites