Using %set_variable_value to define variable

0 votes
asked Jun 20 in Question / help by pmh (140 points)
Hello,

Now I can use %set_variable_value function to define global variables. But I'm afraid that this is not documented feature or bug and it will be fixed in feature releases. So should this function define variables (this functional was planned) or only set values?

This code, for example, will define and initialize global $a:

@startuml
!function $test()
%set_variable_value("$a", "$a initialized")
!endfunction

$test()
A -> B: $a
@enduml

pmh

1 Answer

0 votes
answered Jun 20 by plantuml (198,100 points)
selected Jun 21 by pmh
 
Best answer

So should this function define variables (this functional was planned) or only set values?

I'm not sure to fully understand the question. I would say both : this function does define variable and does also set values.

For example :

@startuml
!function $test()
%set_variable_value("$a", "$a initialized")
!endfunction

!ifdef $a
A -> B : this should not appear, because the variable is not defined
!endif

$test()

A -> B: $a
!ifdef $a
A -> B : the variable is defined
!endif
@enduml

http://www.plantuml.com/plantuml/uml/RO_12i8m38RlUOfiJDXWli0ECdqHoTQK1MetrjI3JsyKUr2y987yV5yo9gLTyor0vNESLTQ8ZNBIjeD3OhtUQHUQ0jiGChTrGtMFLb6Yg52G1xkwWugZAm20IhnZZmt16OydlE20kaZ2jAmvE8oh8cqRqzxZn3FbnBPdB2wqw2jZ38ditd3n0EMm3tKmmN_LD-e7CrgpXvy0

But once again maybe I am missing the point here.

Does it help ?

commented Jun 20 by pmh (140 points)
Hello,

You answer helped me. I just wanted to know if variable definition functional was normal for %set_variable_value in order to use this function correctly.

If this function was created only for set values I would used it this way (first define variable and only than use function):

!global $a = "value 1"

... some code ...

%set_variable_value("$a","value 2")

pmh
...