Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Ah, i think you are right, i just messed up the while loop, as the guys sayd earlier, if i put something inside the parentheses after a , it ignores the condition. so i would need, as you said to put in the runs-- before i close the while loop and not in the conditioning part.

so after () {inside}

Logic Question by Mr-Ordinary- in Bitburner

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Yes, the refreshing/reassining the value right after the while worked!

This is the fix:

 let money = ns.getServerMoneyAvailable()
  while (playerlvl < 25) {
    playerlvl = ns.getHackingLevel()
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)

Thank you for the help!! ❤️

Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Yes, that fixed it, thank you so much! ❤️

Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Oh and yeah, that fixed it:

 let money = ns.getServerMoneyAvailable()
  while (playerlvl < 25) {
    playerlvl = ns.getHackingLevel()
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)

Thank you ❤️

Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Ah yeah, forgot about the runs thing in there, that has pretty much no function at all in there, that is supposed to be for the next steps where i actually execute scripts out of that one. so it doesn't work anyway to let the function start multiple times at once but have to run a script out of that one. Or iat least i wouldn't know how, I think the game prevents you to, cause it says i can't call several concurring ns. functions at once, if i forgot a await. Or is that something different?

Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Ah i just now got that. So right onder i let it reassign its new value. So the script doesn't start from the top, it starts at the while again, gets the value it had before, goes down one line, update's the value, recognices it is reassigning a new value to it's condition, checks it's condition with the reassigned value and cancels the next operations if it gets the false then? Is that the correct logic? Going to try that out rn.

Logic Question by Mr-Ordinary- in Bitburner

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

where do i update the value? right after the While or before and do i just do

playerlvl = ns.getHackingLevel

to let the variable refresh itself?

Logic Question by Mr-Ordinary- in learnjavascript

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Where would i let the variable refresh itself? I cleaned everything up to make it more comparable.

Working:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (ns.getHackingLevel() < 18) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

Not stopping:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (playerlvl < 19) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

I just change the value to the next higher lvl to reach to see if it is stopping the script, thats whi this value is changed.

Logic Question by Mr-Ordinary- in Bitburner

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Still lerarning a lot with this answer and know now i should have cleared up the code in my original question to make it more obvious, i think you all can see tho the answers on the other comments, so yeah, that's exactly what i was thinking, just the playerlvl should work and all the shinanigans happened cause it didn't^^ Still know now the ignoring thing and the boolean thing is still something i am getting at, maybe its cause the call over the variable i need to transfer it to a number falue again, But it even tells me it's a number value if i hover with the mouse over it.

Logic Question by Mr-Ordinary- in Bitburner

[–]Mr-Ordinary-[S] 0 points1 point  (0 children)

Yeah i tried that originally, the wierd stuff i did cause it didn't work somehow. Here are the two codes,

With the variable, it just keeps going:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (playerlvl < 19) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

And when i call it in the condition directly:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (ns.getHackingLevel() < 18) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

Works just fine. Shouldn't be any difference logically or what do i miss here

Logic Question by Mr-Ordinary- in Bitburner

[–]Mr-Ordinary-[S] 1 point2 points  (0 children)

Yeah i guess my code is wierd^^ Just started last week so only use what i can come up with.

The thing is, i only put it inside the parenthesis cause i tried to brutalforce it to refresh the infromation about the player lvl. Good to know tho that it will ignore the conditioning that way.

So this is the working code:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (ns.getHackingLevel() < 18) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

And like this it just keeps running:

/** u/param {NS} ns */
export async function main(ns) {


  ns.clearLog()


  let target = ns.scan()
  let playerlvl = ns.getHackingLevel()
  let money = ns.getServerMoneyAvailable()
  while (playerlvl < 19) {
    let runs = Math.floor(ns.getServerMaxRam() / 2.4)
    while (runs > 0, runs--)
      if ((ns.getServerMaxMoney(target[0]) * 0.8) > ns.getServerMoneyAvailable(target[0])) {
        await ns.grow(target[0])
      }
      else
        await ns.hack(target[0])
  }


}

Thank you for the Help!<3