Var PHP to JS

Hello, how do I proceed to transmit a php variable to RPG MAKER MV on javascript.

I have this example in my head :
< script>
var myvar = < ? $ myvarphp ? >
</ script>

I just do as his ?
Thank you in advance.
Using the shirt PHP tags is not recommended. You should use the full ones instead.

<?php echo $myVar ?>
yes i know but i can do this to retrieve the php var on RPG MAKER ? 
When you echo a value in php, it just prints it to the page. If you print the variable in a script like you did above in the OP, you can get the value in that variable.
Ok i will try this on script command :

$gameVariables.value(21)=goldNot working you know why ?

this is the error :

Invalid Left-Hand side in assignementEdit : ok with this no error but not working :

Code:
$gameVariables.value(21) == gold
Don't do this. Use Ajax.
I think i'm forced to used this because the script call of index.php of game freeze other script. Actualy I call a php page like this before the initialisation :

    <body style="background-color: black">

 

index.php

<?php include('sync.php'); ?> <script type="text/javascript" src="js/libs/pixi.js"></script>        <script type="text/javascript" src="js/libs/fpsmeter.js"></script>        <script type="text/javascript" src="js/libs/lz-string.js"></script>        <script type="text/javascript" src="js/rpg_core.js"></script>        <script type="text/javascript" src="js/rpg_managers.js"></script>        <script type="text/javascript" src="js/rpg_objects.js"></script>        <script type="text/javascript" src="js/rpg_scenes.js"></script>        <script type="text/javascript" src="js/rpg_sprites.js"></script>        <script type="text/javascript" src="js/rpg_windows.js"></script>        <script type="text/javascript" src="js/plugins.js"></script>        <script type="text/javascript" src="js/main.js"></script>sync.php :

Code:
<?phpinclude('config_sql.php');/* SYNC Game */### GOLD = $gameParty.gold()# LEVEL = $gameActors.actor(1)._level# ClassId = $gameActors.actor(1)._classId# XP = $gameActors.actor(1)._exp[1]# Variables = $gameVariables.value(ID)# Switch = $gameSwitches.value(ID)##$user_sync=$bdd->query('SELECT * FROM membre WHERE email="'.$_SESSION['email'].'"');$user=$user_sync->fetch();?><script>var gold=<?php echo $user['gold'] ?>;</script>
Please Please learn how to create an API and then call that from the game.   😀 It would be much better. 
Whats the problem? This is a test, after i do this, and its working now :

<script type="text/javascript">function getUserInfos(arg) {//exemple : SQL TABLE COLONE IS 'gold' use getUserInfos(gold);arg=<?php echo $user['?>arg<?php'] ?>;return arg;}// --></script>i used this script only for start game to initialise last infos, when the game is playing I used this :

ajaxRequest = function(args,variable) {  var retrievedData = "";  var parameters = PluginManager.parameters('Ajax');  var menurl = "menubar.php";  var get_params = args;  var get_variable = variable;t  var xhttp = new XMLHttpRequest();  xhttp.onreadystatechange = function() {    if (xhttp.readyState == 4 && xhttp.status == 200) {      retrievedData = xhttp.responseText;    }  }  xhttp.open("GET", parameters['URL'] + "?" + get_params + get_variable, false);  xhttp.send();  // return the retrieved text  return retrievedData;};And When the game start, start on common event with this request allways  300 wait times.

script commande :

ajaxRequest('gold=',$gameParty.gold());This is a good use ?
setting variables via javascript in php or vice versa is a bad idea. it leads to poorly written code and even poorer maintence. I suggest you learn Ajax and how to write solid testable OO api's
Thank you , today I have followed your advice and it is true Ajax little better now I control what 's going on . I use a simple code to send data via post , and refresh a page.

ajax.js

function writeInDiv(text){    var objet = document.getElementById('ta_div');    objet.innerHTML = text;}function ajax(){    var xhr=null;    if (window.XMLHttpRequest) {        xhr = new XMLHttpRequest();    }    else if (window.ActiveXObject)    {        xhr = new ActiveXObject("Microsoft.XMLHTTP");    }    xhr.open("GET", "menubar.php", false);    xhr.send(null);    writeInDiv(xhr.responseText);        setTimeout("ajax()",1000);}On my second script cons I do not think using the correct method ?

taskscript.js

$(document).ready(function() {function getTask(){$.post('task_core.php',function(donnees) { $('.afficher').html(donnees);})}setInterval(getTask,1000);});
task_core.php

Code:
<?phpinclude('config_sql.php');/* SYNC Game */### GOLD = $gameParty.gold() $gameParty.gainGold() # LEVEL = $gameActors.actor(1)._level $gameActors.actor(1).changeLevel()# ClassId = $gameActors.actor(1)._classId# XP = $gameActors.actor(1)._exp[1] $gameActors.actor(1).changeExp(1000);# Variables = $gameVariables.value(ID)# Switch = $gameSwitches.value(ID)##$user_sync=$bdd->query('SELECT * FROM membre WHERE email="'.$_SESSION['email'].'"');$user=$user_sync->fetch();$task1_sync=$bdd->query('SELECT COUNT(*) FROM task WHERE userId="'.$user['id'].'" AND taskId=1 ');$task1=$task1_sync->fetchColumn();echo $task1."task";if($task1==1){$js_task1=1;}else{$js_task1=0;}?><script>var task1=<?php echo $js_task1 ?>;var gold=<?php echo $user['gold'] ?>;var xp=<?php echo $user['xp'] ?>;var level=<?php echo $user['level'] ?>;</script>

Original thread: https://forums.rpgmakerweb.com/threads/var-php-to-js.50002/