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.
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