globals not being seen

Recurrent H/W and software problems
Post Reply
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

globals not being seen

Post by Stuart »

I seem to have a small problem with some globals not being seen within a sub by some lines of code. In the code below, the globals are seen by the timestamp sub but not by the jscall command, both of which are called from the changeflow sub.

The context is some svg code within a web page that draws a mimic diagram (example attached) as the DOM. The mimic diagram is then updated in real time by javascript code. This code is the sub that updates the parts of the heating system pipework where water is actively flowing, as and when the valve configuration changes.

these are the globals:
waterstatic$ = "cornflowerblue"
waterflow$ = "blue"
I'm using globals to make it easy to change the colour scheme as I refine the design.

The version of the sub below works where the blue colours are specified as quoted strings, but not where they are specified as variables:

Code: [Local Link Removed for Guests]

'==========
sub changeflow (page$,targ$,outcome$)
   'to ensure that the javascript is only applied when the mimic diagram is displayed as that is where the id is found
   'it can be toggled between mimic and a table and generates a (silent) browser error if the id is not found
   if ((web_page$ ="table")AND(page$="M"))or((web_page$="mimic")AND(page$="T")) then end sub

   'this changes the colour of a pipe line according to whether flow is on or off in the pipe:
   if outcome$ = "off" then
     'jscall |document.getElementById("|+targ$+|").setAttribute("stroke", "cornflowerblue");| '<- works
      jscall |document.getElementById("|+targ$+|").setAttribute("stroke", waterstatic$);| '<- does not work
      timestamp "flow "+targ$+" "+outcome$+" "+waterstatic$ '<- but it works here
   else
     'jscall |document.getElementById("|+targ$+|").setAttribute("stroke", "blue");|
      jscall |document.getElementById("|+targ$+|").setAttribute("stroke", waterflow$);|
      timestamp "flow "+targ$+" "+outcome$+" "+" "+ waterflow$
   endif
   end sub
This is the log that shows the attempt to change ch_flow from cornflowerblue to (dark)blue. All flows are initialised to cornflowerblue.

[17/01/24-10:13:58 SRPZhCub:CPbU] displaying web mimic
[17/01/24-10:13:58 SRPZhCub:CPbU] flow boiler_flow on blue '<- correctly reported but not applied
[17/01/24-10:13:58 SRPZhCub:CPbU] flow hw_flow off cornflowerblue
[17/01/24-10:13:58 SRPZhCub:CPbU] flow ch_flow on blue '<- correctly reported but not applied
[17/01/24-10:13:58 SRPZhCub:CPbU] flow ufh_flow off cornflowerblue
[/code]

In the diagram, the left-most blue pipe circuit (c2-c8, r2-r7) which is dark blue remains light blue when the colours are specified as variables.
Screenshot from 2024-01-23 18-10-46.png
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2041
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 437 times
Been thanked: 1342 times
Contact:

Re: globals not being seen

Post by cicciocb »

There is an error in your code as you are sending waterstatic$ as text and not the content of waterstatic$:

This line works :

jscall |document.getElementById("|+targ$+|").setAttribute("stroke", "| + waterstatic$ + |");|

the same for the other variable
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

Re: globals not being seen

Post by Stuart »

Thank you. The curse of the multiple embedded layers of quotes strikes again.
Post Reply