I have formatted the second script so it could be easily read in notepad ++ which is the problematic one, the first is just so you have arrays to work with…Anyways I created this script to replace words with pre-existing numbers in the forms, it works fine cycling through the first key which is “movespeed/movrate” but after when it gets down to str and strrate, it literally cuts off where I have commented //Doesn't get past here?
It get’s initialized through an onClick (it’s a button)
<script type="text/javascript">
var key = new Array();
var val = new Array();
key.push("movespeed");
val.push("1");
key.push("str");
val.push("4");
key.push("dex");
val.push("3");
key.push("int");
val.push("1");
key.push("will");
val.push("2");
key.push("Movrate");
val.push("Mov+1");
key.push("strrate");
val.push("1+str");
key.push("dexrate");
val.push("1+dex+(str/4)");
key.push("intrate");
val.push("1+int");
key.push("willrate");
val.push("1+will");
</script>
Apologies if the above script is messing, it was generated by the page..
<script type="text/javascript">
function Update() {
for (i = 0; i <= key.length; i++) {
if (key[i].indexOf("rate") > -1) { //Search through
for (r = 0; r <= key.length; r++) {
alert("Checked:" + key[r] + " In:" + key[i]);
if (key[i].indexOf(key[r]) > -1) { //Finds out which form it should replace
alert("Passed:" + key[r] + " In:" + key[i]);
var raw = val[i];
for (y = 0; y <= key.length; y++) {
if (key[i] != "movespeed" && key[i] != "Movrate") { //add a check to see if string is not there
//alert("string:"+raw);
//raw=raw.replace(key[y],Number(document.getElementById(key[y]).value));
raw = raw.replace(key[y], document.getElementById(key[y]).value);
//alert("Changed:"+key[y]);
alert(raw);
} else break;
alert("hi");
} //Doesn't get past here?
alert("key[i]:" + key[i] + "Key[r]:" + key[r]);
if (raw.indexOf("Mov") > -1) {
for (x = 0; x <= key.length; x++) {
if (key[x].indexOf("movespeed") > -1) {
raw = raw.replace("Mov", document.getElementById(key[x]).value);
break;
}
}
}
if (raw.indexOf("Lvl") > -1) {
raw = raw.replace("Lvl", document.getElementById('Lvl').value);
}
if (raw.indexOf("Exp") > -1) {
raw = raw.replace("Exp", "0");
//Change this to exp...you also need to add an exp to the formula system, derpy.
}
alert(raw);
if (key[i] == "Movrate") {
document.getElementById("movespeed").value = eval(raw);
} else {
document.getElementById(key[i]).value = eval(raw);
}
break; //So it doesn't keep searching
}
}
}
alert(key[i]);
}
}
</script>
Html(It was generated through the php but it should work fine without having to be generated)
Files<br>======================<br>Basic.xml<br>======================<br><table><tbody><tr><td>Creature Name:</td><td><input type="Text" name="CName" value="Thing" size="10%"></td></tr><tr><td>Level:</td><td><input type="Text" id="Lvl" name="level" onchange="alert('hi')" value="1" size="10%"></td></tr><tr><td>movespeed:</td><td><input type="Text" name="movespeed" id="movespeed" value="1" size="10%"></td></tr><tr><td>str:</td><td><input type="Text" name="str" id="str" value="4" size="10%"></td></tr><tr><td>dex:</td><td><input type="Text" name="dex" id="dex" value="3" size="10%"></td></tr><tr><td>int:</td><td><input type="Text" name="int" id="int" value="1" size="10%"></td></tr><tr><td>will:</td><td><input type="Text" name="will" id="will" value="2" size="10%"></td></tr><script type="text/javascript">var key=new Array();var val=new Array();key.push("movespeed");val.push("1");key.push("str");val.push("4");key.push("dex");val.push("3");key.push("int");val.push("1");key.push("will");val.push("2");key.push("Movrate");val.push("Mov+1");key.push("strrate");val.push("1+str");key.push("dexrate");val.push("1+dex+(str/4)");key.push("intrate");val.push("1+int");key.push("willrate");val.push("1+will");</script><tr><td><input type="button" name="button" value="Update" onclick="Update();"></td><td><input type="submit" value="Save"></td><script type="text/javascript">
logic problem, I used i instead of r, changing it to r fixed it completely. Human mistake, thanks everyone though you guys provided some useful tips I wasn’t aware of: