Changing temperature

Okay. So I found a way to make the temperature 96.8 degrees fahrenheit. But now I need the temperature to change.

I have two attributes, game.temperature = 96 and game.temperature2 = 8. Here's the code in my starting game script.

firsttime {
  msg ("You wake up from your bed.")
}
player.hitpoints = 12
game.temperature = 96
game.temperature2 = 8
game.statusattributes = NewStringDictionary()
player.max = 12
player.statusattributes = NewStringDictionary()
dictionary add (player.statusattributes, "hitpoints", "Hit points: !")
player.changedhitpoints => {
  if (player.hitpoints > 0) {
    msg ("Hits points now " + player.hitpoints + ".")
  }
  else {
    msg ("You are dead!<br/><br/>Your body is being processed and oozed through the intestines!")
    MoveObject (player, Intestines)
    MoveObject (Potion Bag, Dead Room)
    MoveObject (Remote Control, Dead Room)
    player.hitpoints = 0
    DisableTimer (Stomach Acid)
    DisableTimer (Stomach Acid 2)
    EnableTimer (Disable Timer)
  }
}
firsttime {
  SetTimeout (12) {
    MoveObject (player, Mouth)
  }
}
game.tempasstring = game.temperature + "." + game.temperature2 + " degrees F"
dictionary add (game.statusattributes, "tempasstring", "Temp.: !")

I have a string dictionary called status attributes. They make the game have the temperature status.
game.tempasstring = game.temperature + "." + game.temperature2 + " degrees F" Turns the two attributes into a string.
dictionary add (game.statusattributes, "tempasstring", "Temp.: !") is supposed to add the string to a dictionary.

So far it all works, but when you start to change the attributes in the code, absolutely nothing happens. There is no change, but I need change.
I have scripts like this on each OnEnter in the rooms.
game.temperature = 97
I also have a timer called Temperature Timer. It goes off every two seconds. Here's the code for it:

roll = GetRandomInt(1,9)
game.temperature2 = roll

So overall, the game starts off at a 96.8 temperature. When you enter a room, it sets the game.temperature to another number. When 2 seconds pass by, game.temperature changes as well. All of this is to mimic a dragon eating the player.

The first part works. The second part does not work. I even downloaded the game to see if it was just the website acting up. That didn't work. I need help!

Game link here. http://textadventures.co.uk/games/view/nmttplgmnue4vmudzs4ovg/dragon-digestion-vore-game


The line game.tempasstring = game.temperature + "." + game.temperature2 + " degrees F" sets tempastring to be the combination of the two attributes.

When you change those attributes, you need to run that line again to update tempastring.

(I would also suggest using a javascript timer rather than a Quest timer if possible, so that you're not refreshing the page every 2 seconds just to change a status attribute. I think some players would like to have verb menus work correctly)


Thanks mrangel!
How do I do a JavaScript timer?


It would depend if anything depends on the precise temperature - does the decimal part affect the game mechanics?

If it's just for display purposes (which fits with randomising it every 2 seconds) then you could run some javascript like…

var temperature = $('<style>').appendTo('head');
setInterval (function () {
  _pauseMode || temperature.text(".temp::after {content: '."+Math.floor(Math.random()*10)+"°F';}");
}, 2000);

and then in your Quest script, the line to add the status attribute would become:

dictionary add (game.statusattributes, "temperature", "Temp.: <span class=\"temp\">!</span>")

This would cause an extra decimal point to be added to the end of the string when it's displayed, without actually refreshing the page. You also don't need temperature2 (it's a javascript variable now), or tempasstring (because that's done in Javascript rather than Quest).

You could even set it to float up and down, rather than picking a new number every 2 seconds; or so that when the player enters a room with a different temperature, instead of jumping from 97.6 to 98.6 it would take a second or two going through all the numbers in between. I'm thinking that would feel more realistic from the player's point of view, but not sure if it would be worth the effort.

Hmm…

var target;
var update = updateStatus;
var tempwhole;
var tempdecimal;
var tempdisplay;
updateStatus = function (text) {
  update(text);
  tempdisplay = $('.temp');
  if (tempdisplay.length) {
    target = parseInt(tempdisplay.text());
    if (!tempwhole) {tempwhole = target;}
    if (!tempdecimal) {tempdecimal = Math.floor(Math.random()*10);}
  }
  tempdisplay.text(tempwhole + '·' + tempdecimal + '°F');
};
setInterval(function () {
  if (tempdisplay) {
    if (Math.random()*14 + 4*(target-tempwhole) - 2 >= tempdecimal) tempdecimal++;
    if (Math.random()*14 + 4*(target-tempwhole) - 2 < tempdecimal) tempdecimal--;
    if (tempdecimal == 10) {tempdecimal = 0; tempwhole++;}
    if (tempdecimal == -1) {tempdecimal = 9; tempwhole--;}
    tempdisplay.text(tempwhole + '·' + tempdecimal + '°F');
  }
}, 220);

I think that would make a number that bobs up and down slowly, floating close to the actual 'temperature' status attribute. It would mean that Quest doesn't have the exact number, but if you're not basing the game mechanics on it, this should be more stable.

This more complex version could be implemented by putting a compressed version:

JS.eval("$(function(){var a,b,c,d,e=updateStatus;updateStatus=function(f){e(f),d=$('.temp'),d.length&&(a=parseInt(d.text()),!b&&(b=a),!c&&(c=Math.floor(10*Math.random()))),d.text(b+'\xB7'+c+'\xB0F')},setInterval(function(){d&&(14*Math.random()+4*(a-b)-2>=c&&c++,14*Math.random()+4*(a-b)-2<c&&c--,10==c&&(c=0,b++),-1==c&&(c=9,b--),d.text(b+'\xB7'+c+'\xB0F'))},220)});")

in your UI initialisation script, and adding temperature to the status attributes with the <span> as I mentioned above. I haven't tested this yet because I'm typing on my phone; but think it could be a good starting point for adding cosmetic alterations to a status attribute.


Okay, I'll see what I can do.


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

Support

Forums