I don't know what to do with this script.

I tried making a script to control the spawn rate of the monsters. I don't know what I'm doing wrong.

Nothing is working. Well, the "after entering room" script is working, but nothing else is working.

Here is the code, I guess.

Start script
Ffgh

game.spawn = false
game.spawncount = 0
game.count2 = 0
if (game.count2 = 1) {
  game.spawn = false
}
game.change => {
  if (game.count2 = 2) {
    game.spawn = false
  }
  if (game.count2 = 3) {
    game.spawn = false
  }
}
game.change2 => {
  if (game.count2 = 4) {
    game.count2 = 0
  }
}
player.changed3 => {
  if (player.count2 > 6) {
    msg ("Hits points now " + player.hitpoints)
    msg ("You are dead!")
  }
}
player.critdesc = "You attack #target# with your bare hands and get a critical (#hits# hits)."
player.attackdesc = "You attack #target# with your bare hands and hit (#hits# hits)."
player.missdesc = "You swing wildly and entirely miss #target#."

Enter and spawn script
Dfhhj

firsttime {
  game.spawn = false
}
if (game.spawn = false) {
  SpawnZombie (this)
}
game.count2 = game.count2 + 1

Any help is appreciated. Thanks.


The start script doesn't set any of those attributes up?

They're set up on my first turn when I drop that script into a fresh game.

image


"You attack #target# with your bare hands and get a critical (#hits# hits)."

I don't know what this is supposed to do, unless you meant to put:

"You attack "+target+" with your bare hands and get a critical ("+hits+" hits)."

...but that will only work if called by a script where two local variables are defined: target and hits. (I'm not saying it's not. Just a word of warning.)


What is it doing, and what is it not doing?


The player descriptions are extra. Forget them.

I'll quote myself. "Well, the "after entering room" script is working, but nothing else is working." Yeah, a few of the attributes cannot be set to a script, and/or are not working.

And just wondering, how is your new save system coming along? Is it working?


How are you calling game.change, game.change2, and player.changed3?

And is it spawning something when game.spawn = false?


I wasn't messing with a save system.

I was messing with a transcript function, and a way to save the Log's text to a file automatically. (They both work, thanks to mrangel!)

I think maybe Anonynn was talking about a save system, but I'm just guessing.


@The anonynn Oh, cool.

Well, what it was supposed to do, was to only spawn zombies when 'game.spawn = false'. The other types of code were just me trying and failing to get this all to work. I tried putting it in the initialisation script to, but nothing.


Add this to the scripts when you think game.spawn should be false:

msg("<hr/>DEBUGGING: game.spawn = "+game.spawn+"<hr/>")

It will print:


DEBUGGING: game.spawn = true

OR



DEBUGGING: game.spawn = false

I already know it's not working. But I'll give it a go anyway.


Yeah. The game knows what game.spawn is. But it won't set to game.spawn = false when it should.

I also made a command called 'Check1', that prints:

msg ("You are count " + game.count2 + ".")

when typed in.

The count2 counter does not reset either.


In the start script, put this:

game.changedspawn => {
  msg("game.spawn just changed to "+game.spawn)
  Log("game.spawn just changed to "+game.spawn)
}

The Log won't help you online, of course.

You could do:

JS.alert("game.spawn = "+game.spawn)

(Those popups will probably drive you crazy, though!)


You could also put that on a game turn script, if you wanted to really get down and dirty.


I said I already did that.

I just put the message in the "on enter" script, after everything else.


Oh, whoops!

I missed it when you said you got it.

Rock on!


What.
It's still broken. (I have to remember to say "did that" and not "got it"...)
None of the scripts in the start script are working, so I was just seeing if someone had a second solution.

Can you set a script to another script with JavaScript?


Can you set a script to another script with JavaScript?

Err...

Umm...

Yeah? But it's best to avoid it.

You'd need to set up a normal function in Quest (preferrably with only one parameter), then call the function via an ASLEvent() from JS (which is being called from Quest through some Chromium browser interface thingy)...

Wait.

Okay. My brain froze up for a second. What were we talking about?

Oh yeah!

  <function name="JsTest" parameters="param">
    msg("DEBUGGING MESSAGE: Running JsTest")
    msg("DEBUGGING MESSAGE: JsTest("+param+")")
    game.js_test_variable = param
    msg("DEBUGGING MESSAGE: game.js_test_variable is now set to: "+game.js_test_variable+".")
  </function>

Then, you use JS to pass the string you enter through an ASLEvent to the Quest function:

JS.ASLEvent("JsTest","Hello, jmne!")

OR

JS.eval("ASLEvent('JsTest','Hello,jmne!');")

OR

JS.eval("var testVar = prompt('Enter the test variable.');ASLEvent('JsTest',testVar);")

OR, if you actually want a JS function defined:

JS.eval("setTestVar = function(tstVar){ASLEvent('JsTest',tstVar);};")

After that, you could simply:

JS.setTestVar("Hello, jmne!")

Then, after about 1 or 2 seconds, you could:

msg(game.js_test_variable)

...and that should print:

Hello, jmne!

More on point, what are you doing with those attributes?

How are they being called?

You are setting them up in the start script, but none of the code you've posted calls any of them.


  • game.change
    You would have to do something like invoke(game.change) to run this (I think).

  • game.change2
    You would have to do something like invoke(game.change2) to run this one, too (again, I think).

  • game.changed3
    If you have an attribute named game.3 (which you might, but I don't think Quest will allow numbers for attribute names), this would run that script when game.3 changed.

So is game.changed3 right then?

What's the difference? I can't tell the difference.


Do you have a game.3 set up?


Oh... Is it only the name that's messed up?
My bad... I may have to experiment more...


Hrmm?

I didn't say that...

I was asking if game.3 is a thing. If it isn't, game.changed3 has no game.3 to watch to see if its value changes.


Alright. I have this now.

game.spawn = false
game.spawncount = 0
game.count2 = 0
if (game.count2 = 1) {
  game.spawn = false
}
game.change => {
  if (game.count2 = 2) {
    game.spawn = false
  }
  if (game.count2 = 3) {
    game.spawn = false
  }
}
game.changedcount2 => {
  if (game.count2 = 4) {
    game.count2 = 0
  }
}

I still don't know what I'm doing. What do I have to set now?


Hey.

Please explain this. (And I don't think invoke is an actual function...)

You would have to do something like invoke(game.change) to run this (I think).

You're setting up game.change as a script attribute:

game.change => {
  if (game.count2 = 2) {
    game.spawn = false
  }
  if (game.count2 = 3) {
    game.spawn = false
  }
}

When does Quest call this script?

How does it ever run?


invoke is a script that runs a script.

http://docs.textadventures.co.uk/quest/scripts/invoke.html


So, I have no idea how game.change is called during your game (if ever), and I was pointing out that one way to do that would be invoke(game.change).

Of course, you'd probably have to check the debugger to see if game.count2 was 2 or 3 (or something else), and if it then set game.spawn to false when applicable.


Instead of all that code you've got, I'd try:

game.spawn = false
game.spawncount = 0
game.count2 = 0
game.changedcount2 => {
  switch(game.count2){
    case(1,2,3){
      game.spawn = false
    }
    case(4){
      game.count2 = 0
    }
  }
}

NOTE: I'm not sure what your code is doing, but, if you've got the basics correct, this should work.


It's not working when I paste it in.
It just says error.

invoke (script)


usage of 'invoke' and 'do' Scripts/Functions:


invoke (NAME_OF_OBJECT.NAME_OF_SCRIPT_ATTRIBUTE)

for example:

invoke (game.start)


invoke (NAME_OF_SCRIPT_Variable)

for examples:

// I think this works but it might not:
script_variable = game.start
invoke (script_variable)

// this does work:
script_variable => msg ("hi")
invoke (script_variable)


do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE")

for example:

do (game, "start")

// or:

object_variable = game
script_name_as_string_variable = "start"
do (object_variable, script_name_as_string_variable)


make sure your input for the 'invoke' and/or 'do' is an actual/existing Script VARIABLE in your game and that you're correctly doing its syntax properly.


Sorry, I've been flu-ridden (it's my first flu, too, and it SUCKS).


...and HK is awesome for explaining invoke(). (You the man, HK!)


I was only pointing out that scripts were created (like game.change), but never called. Then, I explained how to call a script. (You could invoke(game.change).)

Again, though, I don't think this will help you here.


I believe you can change your script:

game.spawncount = 0
game.count2 = 0
if (game.count2 = 1) {
  game.spawn = false
}
game.change => {
  if (game.count2 = 2) {
    game.spawn = false
  }
  if (game.count2 = 3) {
    game.spawn = false
  }
}
game.changedcount2 => {
  if (game.count2 = 4) {
    game.count2 = 0
  }
}

to this:

game.spawn = false
game.spawncount = 0
game.count2 = 0
game.changedcount2 => {
  switch(game.count2){
    case(1,2,3){
      game.spawn = false
    }
    case(4){
      game.count2 = 0
    }
  }
}

K V That doesn't work either. The formatting is off.


What formatting is off?

It drops right in for me.

image


image


image


Try this one with debugging messages:

game.spawn = false
game.spawncount = 0
game.count2 = 0
game.changedcount2 => {
  msg ("DEBUGGING: Calling game.changedcount2.")
  msg ("DEBUGGING: game.count2 is now: "+game.count2)
  switch (game.count2) {
    case (1,2,3) {
      game.spawn = false
    }
    case (4) {
      game.count2 = 0
    }
  }
  msg ("DEBUGGING: game.spawn = "+game.spawn)
}


If that doesn't work in your game, try this example game to see it all working:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="test">
    <gameid>f36c14c6-3d92-482f-bb2d-96361074cb7b</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <start type="script"><![CDATA[
      JS.setCommands ("increase count2")
      game.spawn = false
      game.spawncount = 0
      game.count2 = 0
      game.changedcount2 => {
        msg ("DEBUGGING: Calling game.changedcount2.")
        msg ("DEBUGGING: game.count2 is now: "+game.count2)
        switch (game.count2) {
          case (1,2,3) {
            game.spawn = false
          }
          case (4) {
            game.count2 = 0
          }
        }
        msg ("DEBUGGING: game.spawn = "+game.spawn)
      }
    ]]></start>
    <commandpane />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[{command: Increase count2}<br/><br/>]]></description>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <command name="inc_cnt2">
    <pattern>increase count2</pattern>
    <script>
      game.count2 = game.count2 + 1
    </script>
  </command>
</asl>

Did you get it working?


Part way working. The count2 is finally resetting. Don't know why. Your code still is not working.


Did you edit in full Code View?

If so, it needs to be CDATA:

    <start type="script"><![CDATA[
      JS.setCommands ("increase count2")
      game.spawn = false
      game.spawncount = 0
      game.count2 = 0
      game.changedcount2 => {
        msg ("DEBUGGING: Calling game.changedcount2.")
        msg ("DEBUGGING: game.count2 is now: "+game.count2)
        switch (game.count2) {
          case (1,2,3) {
            game.spawn = false
          }
          case (4) {
            game.count2 = 0
          }
        }
        msg ("DEBUGGING: game.spawn = "+game.spawn)
      }
    ]]></start>

But, if you have it working, it's probably wise not to mess with it. (I just realized that CDATA was probably what was getting you.)


I used to do it like 'KV', but now I prefer to do it like this:

I like showing it like this, just so they can see that the 'cdata' is containing the scripting, and so I can easily check/see if I messed up any of the syntax with it (missing: ']', '[', '!', etc, usually, lol) and/or completely forgot to add the 'cdata' if/when it's needed (lol), but it takes up more lines, but it makes it easier to read and spot-mistakes:

<start type="script">

  <![CDATA[

    JS.setCommands ("increase count2")
    game.spawn = false
    game.spawncount = 0
    game.count2 = 0
    game.changedcount2 => {
      msg ("DEBUGGING: Calling game.changedcount2.")
      msg ("DEBUGGING: game.count2 is now: "+game.count2)
      switch (game.count2) {
        case (1,2,3) {
          game.spawn = false
        }
        case (4) {
          game.count2 = 0
        }
      }
      msg ("DEBUGGING: game.spawn = "+game.spawn)
    }

  ]]>

</start>

Well...

Quest does that, not me.


I can make a new game and paste in HK's start script:

<asl version="550">

  <include ref="English.aslx"/>
  <include ref="Core.aslx"/>

  <game name="NewTest (CDATA)">
    <gameid>cec840ed-55f9-4793-b3bd-d3272554c160</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    
    <start type="script">

  <![CDATA[

    JS.setCommands ("increase count2")
    game.spawn = false
    game.spawncount = 0
    game.count2 = 0
    game.changedcount2 => {
      msg ("DEBUGGING: Calling game.changedcount2.")
      msg ("DEBUGGING: game.count2 is now: "+game.count2)
      switch (game.count2) {
        case (1,2,3) {
          game.spawn = false
        }
        case (4) {
          game.count2 = 0
        }
      }
      msg ("DEBUGGING: game.spawn = "+game.spawn)
    }

  ]]>

</start>

  </game>

  <object name="room">
    <inherit name="editor_room" />

    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>

</asl>

After switching back to GUI and adding something (in this case, I enabled the commands pane, but I just did a different test where I only added a room description, and it still does the same thing), Quest turns it into this:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="NewTest (CDATA)">
    <gameid>cec840ed-55f9-4793-b3bd-d3272554c160</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <start type="script"><![CDATA[
      JS.setCommands ("increase count2")
      game.spawn = false
      game.spawncount = 0
      game.count2 = 0
      game.changedcount2 => {
        msg ("DEBUGGING: Calling game.changedcount2.")
        msg ("DEBUGGING: game.count2 is now: "+game.count2)
        switch (game.count2) {
          case (1,2,3) {
            game.spawn = false
          }
          case (4) {
            game.count2 = 0
          }
        }
        msg ("DEBUGGING: game.spawn = "+game.spawn)
      }
    ]]></start>
    <commandpane />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
</asl>

oh... my bad... didn't realize this was because of quest's formatting-reversion (I hate it too... which is why I avoid toggling between the GUI/Editor and Code View modes).

my apologies, KV.

(I like the format, as I think it's easier for new people to read/understand it. When I first started coding, I liked being as concise as possible with my code lines, but now I like having spacing and etc stuff to make it easier to see/read/edit/understand/etc)


Oh, you're cool, HK!

...and you're definitely right about the spacing making it easier to see what is actually happening.


Oh, you were right, K.V.! IT FINALLY WORKS NOW!

Thank you, everyone!


anytime you work in code, and you use the '<' and/or '>' characters/symbols in your scripting, you need to put in the 'cdata' tags


Whoo-hoo!


I'm also pretty sure (to tack on to HK's knowledge-nugget) that you can make something CDATA that doesn't need to be, and Quest won't mind at all. (I like safety nets!)


I'm using the online version still, by the way...


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums