retrieve a variable

67 views
Skip to first unread message

Elliot

unread,
Mar 2, 2018, 11:35:02 AM3/2/18
to Skulpt

Thank you for this nice project that works well. I would like to retrieve in a variable table the result compute by skulpt. How do I proceed ?

Thank you for your reply.


example :


<textarea id="code" rows="10" cols="50">u=75
n=0
while u>64:
  print n,u
  n=n+1
 u=0.96*u+2
</textarea>
<button onclick="playcode()">Jouer le code</button>
<pre id="output"></pre>
<script type="text/javascript">
function playcode(){
 
function outf(text) {
   
var mypre = document.getElementById("output");
    mypre
.innerHTML = mypre.innerHTML + text;
}
function builtinRead(x) {
   
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
   
throw "File not found: '" + x + "'";
   
return Sk.builtinFiles["files"][x];
}
var prog=document.getElementById("code").value;
var mypre = document.getElementById("output");
  mypre
.innerHTML = '';
 
Sk.canvas = "mycanvas";
 
Sk.pre = "output";
 
Sk.configure({output:outf, read:builtinRead});
 
try {
   
eval(Sk.importMainWithBody("<stdin>",false,prog));
 
}
 
catch(e) {
    alert
(e.toString())
 
}
}
</script>



Message has been deleted

Elliot

unread,
May 14, 2018, 6:28:05 PM5/14/18
to Skulpt
Hello
I can get the value of u and n in a table but I have 4 times the value. What piece of code do I have to modify?

thank you


<textarea id="code" rows="10" cols="50">u=75
n=0
while u>64:
  print n,u
  n=n+1
  u=0.96*u+2
</textarea>
<button onclick="playcode()">Jouer le code</button>
<pre id="output"></pre>
<script type="text/javascript">
function playcode(){
 
function outf(text) {
   
var mypre = document.getElementById("output");
    mypre
.innerHTML = mypre.innerHTML + text;
    if(aai%4==0){aaa.push(Sk.ffi.remapToJs(Sk.globals["n"]),Sk.ffi.remapToJs(Sk.globals["u"]));
Reply all
Reply to author
Forward
0 new messages