Dynamic reference to mesh

Users who are viewing this thread

Hello
Im trying to dynamically add a mesh to a tableau material.
Inside a script I'm "dynamically" adding a mesh with a texture to an iten on item init. The meshes with the naming convention body_type_{0-1}_part_{0-9} exist in a brf file, and it works fine:
Python:
(troop_get_type, ":num_skin", ":troop_no"),
(assign, reg0, ":num_skin"),
(assign, reg1, ":armor_kind"),
(str_store_troop_face_keys, s1, ":troop_no"),
(face_keys_get_face_texture, reg2, s1),
(cur_item_add_mesh_with_material, "@body_type_{reg0}_part_{reg1}", "@body_texture_type_{reg0}_no_{reg2}"),

But when trying to replicate this method referencing a mesh that is defined in module_meshes it does not recognize it, inside module_tableau_materials:
Python:
(store_script_param, ":troop_no", 1),
(troop_get_type, ":num_skin", ":troop_no"),
(assign, reg0, ":num_skin"),
(str_store_troop_face_keys, s1, ":troop_no"),
(face_keys_get_face_texture, reg1, s1),

(display_message,"@mesh_plane_body_{reg0}_no_{reg1}",0xFFCCFF44),
#(assign, ":skin_plane", "@mesh_plane_body_{reg0}_no_{reg1}"),

(set_fixed_point_multiplier, 100),

(init_position, pos1),
(position_set_z, pos1, 10),
#(cur_tableau_add_mesh, ":skin_plane", pos1, 0, 0),
(cur_tableau_add_mesh, "@mesh_plane_body_{reg0}_no_{reg1}", pos1, 0, 0),
Inside the module_mesh:
Python:
("plane_body_0_no_0", 0, "plane_body_0_no_0", 0, 0, 0, 0, 0, 0, 10, 10, 10),
...
("plane_body_0_no_9", 0, "plane_body_0_no_9",  0, 0, 0, 0, 0, 0, 10, 10, 10),

have tried without the '@' at the start, and assigning an auxiliary variable ':skin_plane' but the compiler just shows:
ERROR: Illegal Identifier:mesh_plane_body_{reg0}_no_{reg1}

with the '@' instead, the compiler does not complain, but the game does not show the added material.
while adding the line manually works but its not dinamic:
Python:
(cur_tableau_add_mesh, "mesh_plane_body_0_no_4", pos1, 0, 0),#the 4th one for example

Any way to concatenate the variables and choose a dynamic mesh for tableau, or any other element existing with an ID like scripts?
 
Last edited:
Use str_store_string, s2 or whatever, instead of assign and it should work.

Strings cant be stored in local variables, only integers can. Assigning a string to a local variable rather than a string register (e.g. s21 or whatever) will work because s0-63 are themselves just slots for integers, but its not recommended, and doesnt process the {reg2} part of the string, while str_store_string does.
 
Thanks
i tried like this but still no luck:

Code:
(str_store_string, "$planebody", "@meshplanebody{reg0}no{reg1}"),
(str_store_string, s65, "@mesh_planebody0no4"),
(str_store_replace_spaces_with_underscores, s65, "@mesh_planebody0no4"),
#tried to prevent any underscore from turning into a space


(cur_tableau_add_mesh, "$planebody", pos1, 0, 0),
(cur_tableau_add_mesh, s65, pos1, 0, 0),

Even removed the {regs} from the equation and cant seem to call the mesh from a variable
 
What you're doing is not working, because "mesh_plane_body_0_no_0" is not a string.
It's an ID and IDs are numbers.
You can't do string operations on IDs, but you can do math on them.
For example, if you take "mesh_plane_body_0_no_0" and you add 5 to it, you will get mesh_plane_body_0_no_5 (because that's the order of meshes that you've set in module_meshes.
See how math is done on id ranges in vanilla, for example look how they operate on troops - ladies_begin, ladies_end.

Let's say you declare a bunch of meshes, in a format of mesh_plane_body_Y_no_X:
mesh_plane_body_0_no_0
mesh_plane_body_0_no_1
mesh_plane_body_0_no_2
mesh_plane_body_1_no_0
mesh_plane_body_1_no_1
mesh_plane_body_1_no_2
mesh_plane_body_2_no_0
mesh_plane_body_2_no_1
mesh_plane_body_2_no_2
the math is as follows:
take mesh_plane_body_0_no_0 (1st on the list)
You can add 1 to it, and it will increase X by 1.
You can add 3 to it, and it will increase Y by 1.
Let's say you want X=2 and Y=3.
You add 2+3*3=11 to mesh_plane_body_0_no_0 and you will get mesh_plane_body_3_no_2
 
Last edited:
What you're doing is not working, because "mesh_plane_body_0_no_0" is not a string.
It's an ID and IDs are numbers.
You can't do string operations on IDs, but you can do math on them.
For example, if you take "mesh_plane_body_0_no_0" and you add 5 to it, you will get mesh_plane_body_0_no_5 (because that's the order of meshes that you've set in module_meshes.
See how math is done on id ranges in vanilla, for example look how they operate on troops - ladies_begin, ladies_end.

Let's say you declare a bunch of meshes, in a format of mesh_plane_body_Y_no_X:
mesh_plane_body_0_no_0
mesh_plane_body_0_no_1
mesh_plane_body_0_no_2
mesh_plane_body_1_no_0
mesh_plane_body_1_no_1
mesh_plane_body_1_no_2
mesh_plane_body_2_no_0
mesh_plane_body_2_no_1
mesh_plane_body_2_no_2
the math is as follows:
take mesh_plane_body_0_no_0 (1st on the list)
You can add 1 to it, and it will increase X by 1.
You can add 3 to it, and it will increase Y by 1.
Let's say you want X=2 and Y=3.
You add 2+3*3=11 to mesh_plane_body_0_no_0 and you will get mesh_plane_body_3_no_2
Thanks!
I did what you said and its working, since i dont know exactly how many textures are going to be for each skin (might have more for ones and less for others), i just did Y in a try else

Python:
("armor_transparent", 0, "base_heraldic_body", 512, 512, 0, 0, 0, 0, [
    (store_script_param, ":troop_no", 1),
    (troop_get_type, ":num_skin", ":troop_no"),
    (assign, reg0, ":num_skin"),
    (str_store_troop_face_keys, s1, ":troop_no"),
    (face_keys_get_face_texture, reg1, s1),

    (assign, ":body_planes_begin", "mesh_plane_body_0_no_0"),
    (try_begin),
      (eq,":num_skin",1),
      (assign, ":body_planes_begin", "mesh_plane_body_1_no_0"),
    (else_try),
      (eq,":num_skin",2),
      #(assign, ":body_planes_begin", "mesh_plane_body_2_no_0"),
    (try_end),
    (store_add, reg0, ":body_planes_begin", reg1),
    (display_message,"@{!}BODY PLANES BEGIN: {reg0}",0xFF4444CC),

    (call_script, "script_agent_troop_get_banner_mesh", -1, ":troop_no"),
    (assign, ":banner_mesh", reg0),

    (set_fixed_point_multiplier, 100),

    (init_position, pos1),
    (position_set_z, pos1, 10),
    (cur_tableau_add_mesh, reg0, pos1, 0, 0),
    (init_position, pos3),
    (position_set_z, pos3, 30),
    (position_set_x, pos3, 0.02),
    (position_set_y, pos3, 0),
    (position_set_scale_x, pos3, 0.02),
    (position_set_scale_y, pos3, 0.02),
    (position_set_scale_z, pos3, 0.02),
    (cur_tableau_add_mesh, ":banner_mesh", pos3, 0, 0),
    (cur_tableau_set_camera_parameters, 0, 200, 200, 0, 100000),
  ]),

I guess i could fill the gaps with placeholders so theres a fixed amount of meshes for each skin, but that would be just more elegant code i suppose.
Thanks
 
Yes, that will work too.
It's code, it's flexible. There is always more than 1 valid solution.
And "elegant" is always a matter of personal taste anyway!
 
Back
Top Bottom