Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script reload on leaving?

35 views
Skip to first unread message

jonas.t...@gmail.com

unread,
Nov 14, 2017, 5:34:28 AM11/14/17
to
This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?

It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.

<!DOCTYPE html>
<html>
<head>
<meta http-Equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script>
function createStruct() {
newword=true;
beeninside=false;
oldlevel=-1;
deeplevel = -1;
wordlevel= -1;
inserted = false;
leftstruct = "[";
rightstruct = "]";
endstruct = "*";
separator = " ";
subseparator = "";
newString= "";
stringPrevMem = "";
stringMem = "";
posStructString="";
//Get values to read in
encodedString = document.getElementById("encodedText").value;
mystr = document.getElementById("inputTextToSave").value;
//Split string into words to read in
strArr = mystr.split(separator);
//Search words
for (var x = 0; x < strArr.length; x++) {

newString=strArr[x];
stringInserted=false;
searchItem(newString);
}
printArray();
alert("closing script");
}

function searchItem(newString) {
oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
while (z < encodedString.length && stringInserted==false) {

if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
// alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
// alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "*") {
//decoded word in memory
newword=true; beeninside=false;
// alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
} else {
stringMem += encodedString.charAt(z);
newSubString=newString.substring(0,stringMem.length);
if (newSubString==stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
}
else if (newSubString>stringMem && newword==true && beeninside==false) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
newword=false;beeninside=true;
stringPrevMem = stringMem;
}
else if (newSubString<stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
checkWhatTOInsert();
}
}
z++;
}
}


function checkWhatTOInsert(){
putString="";
if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
else {insertString = newString.substring(newSubString.length, newString.length);}

insertChar = insertString.split('');
for (var m=0;m<insertChar.length;m++){
putString+="["+insertChar[m];
}
putString+="*";
for (var m=0;m<insertChar.length;m++){
putString+="]";
}
encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
document.getElementById("encodedText").value=encodedString;
stringInserted=true;
// alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
}

function insertSubstring(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
}

function printArray() {

encodedString = document.getElementById("encodedText").value;
stringMem="";oldlevel=-1;deeplevel=-1;
for (var z = 0; z < encodedString.length; z++) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
} else if (encodedString.charAt(z) == "*") {
document.getElementById("decodedText").value+=stringMem+"\n";

} else {
stringMem += encodedString.charAt(z);
}
}
}
</script>
<body onload="printArray();">
<form onSubmit="createStruct();">
<input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
</form>
<br>
<Font size="4">DEBUG</Font><br>
<textarea id="debug" cols="80" rows="3"></textarea><br>
<br>
<Font size="4">INSERT IN STRUCTURE</Font><br>
<textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
<br>
<Font size="4">STRUCTURE</Font><br>
<textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
<br>
<Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
<textarea id="decodedText" cols="80" rows="12"></textarea><br>
</body>
</html>



Jonas Thörnvall

unread,
Nov 14, 2017, 5:44:36 AM11/14/17
to
I can't see how these could do anything wrong, writing to textarea what am i missing?

document.getElementById("encodedText").value=encodedString;

Jonas Thörnvall

unread,
Nov 14, 2017, 7:45:45 AM11/14/17
to
Changed to button problem fixed.
<button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>

Julio Di Egidio

unread,
Nov 14, 2017, 7:47:17 AM11/14/17
to
On Tuesday, November 14, 2017 at 11:34:28 AM UTC+1, Jonas Thörnvall wrote:

> why does the script reload after it ended?

Which one? You have an onload and an onsubmit...

> <form onSubmit="createStruct();">

I am guessing createStruct fails and you get the form submitted.

Anyway the code is littered with bugs...

Julio

Jonas Thörnvall

unread,
Nov 14, 2017, 7:52:34 AM11/14/17
to
Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
document.getElementById("decodedText").value="";

Jonas Thörnvall

unread,
Nov 14, 2017, 7:53:48 AM11/14/17
to
The case with words that actually smaller or bigger in array are special cases.

Jonas Thörnvall

unread,
Nov 14, 2017, 8:33:38 AM11/14/17
to
http://anybase.co.nf/insert/chessbook.html

I think it will work tomorrow and put them correct between paragraphs ...maybe i will use it to create a chessbok where i can read in chessgames in an hieraki and each position gets a probability of win.

It is sort of treestructure without restrictions except for memory, it is like treestucture without depth restrictions. And it don't allocate any memory, you really do not keep the full tree in memory just read forward as you search in it. Right now it read the full structure into memory, to insert new string items.



Jonas Thörnvall

unread,
Nov 14, 2017, 3:04:15 PM11/14/17
to
An AI that work on 1KB of memory, doing alot of swapping....

Jonas Thörnvall

unread,
Nov 14, 2017, 7:52:33 PM11/14/17
to
Just looking at the structure one can see that the paragraphs is unnecessary, the left paragraphs is unecessary altogether no need for left object and the right closing ones can be replaced by numbers denoting the level. But it would be cumbersome start the implementation a bit to abstract.

But i think i can start to remove the paragraphs once the program work flawless.
0 new messages