0
The idea is that while running a while loop in Python code, it will receive a value array of a function in Javascript and will work on those values. Example:
In the Python file (in this case, the userCommand array will always be renewed with each loop):
while True:
userCommand = ....vetor recebido do JS no formato [command, arg1, arg2, arg3]....
if(userCommand[0] == 1):
functionA(userCommand[1], userCommand[2])
userCommand[0] = 0
elif(userCommand[0] == 2):
functionB(userCommand[1], userCommand[3])
userCommand[0] = 0
elif(userCommand[0] == 3):
functionC(userCommand[3])
userCommand[0] = 0
etc...
And in the Javascript file, something like that:
function(number1, number2)
{
command = [3, number1, number2]
...enviar para o arquivo Python de modo que userCommand = command....
}
Passes the vector as JSON.
– Augusto Vasques
If you could explain a little more about what you’re trying to do, maybe we can suggest a better way to do this implementation. For me what you described there is a client-server architecture. And these
ifs
that it has in its python code would be the routes...with http method (get post) for each operation.– Danizavtz
For example when the user clicks a button on the web page. The javascript will then trigger that function with some parameters, for example the coordinates of the click screen, will store the values in an array and send it to the python file that is already running, stuck in a while, in an infinite loop. The userCommand variable in the Python file will always be waiting to receive something from JS
– zepolik
The problem then is not what to pass, but how to pass the data. This implies knowing where to pass the data. This python program is running on the client or is running on the server?
– Augusto Vasques