The fire is already lit

OurJud
02 Nov 2016, 20:54

I'm getting worse at this thing, not better.

I've spent almost three hours trying to create a script for a command which checks if the fire is lit, and if it is tells the player so.

This is what I have and it won't work.

if (Got(wood)) {
  play sound ("firecrackling3.mp3", false, true)
  msg ("Fire lit.")
  SetObjectFlagOn (player, "firelit")
}
else if (GetBoolean(player, "firelit")) {
  msg ("Fire's already lit.")
}
else {
  msg ("No fuel.")
}

The Pixie
02 Nov 2016, 21:31

Do you mean a command for lighting the fire? The best way to approach scripting a command, in my opinion, is to list all the conditions that must be met, and for each one test if it is NOT met. Then at the end of the script, actually do it. You have two condition - must have fuel and not be lit - so test if there is not fuel, then test if it is lit, then do it.

if (not Got(wood)) {
  msg ("No fuel.")
}
else if (GetBoolean(player, "firelit")) {
  msg ("Fire's already lit.")
}
else {
  play sound ("firecrackling3.mp3", false, true)
  msg ("Fire lit.")
  SetObjectFlagOn (player, "firelit")
}

OurJud
02 Nov 2016, 21:35

You're a genius!

I'm going to study that with a fine tooth comb and try and get my head around it.

Thank you!

I automatically check they DO have the things they need. Didn't know I should be checking what they DON'T have first.


hegemonkhan
04 Nov 2016, 10:08

if no wood (1 operation):
-> msg (" no fuel")
-> end
if yes wood (implied/understood):
-> if fire lit (one operation):
->-> msg ("The fire's already lit")
->-> end
-> if fire not lit (3 operations):
->-> play sound
->-> msg ("fire lit")
->-> set the fire to being lit
->-> end


2 terms/variables/factors:
-> wood
-> lit


N = number of terms/variables/factors
// N = 2

2^N = number of conditions/combinations/steps
// 2^2 = 4


4 combinations/conditions/steps:

-> yes wood and yes lit (1 operation) // #2
-> yes wood and no lit (3 operations) // #3
-> no wood and yes lit (0 operations) // (nulled / skipped-ignored entirely / irrelevant, #2 and #3 is this split apart, so they cover this condition/combination/step already): N/A
-> no wood and no lit (1 operation) // #1


it makes it more simple for yourself, to eliminate (get done and out of the way) all of the simple conditions/combinations that don't do much, first, ending up with doing your main most complex/involved condition/combination/step, last, after everything else is checked for.


  1. your main most complex/involved condition/combination/step is to light the fire (3 operations: play sound, prompt user, and set fire to being lit), so you want to do this condition/combination/step, last

  1. well, if you don't have any wood, you can't light the fire, so you want to do this condition/combination/step, first.

N/A. (not having wood but having a lit fire, is doubly irrelevant to getting to the lighting a fire: you don't have wood, so no lighting a fire, the end, and even if pretending that not having wood is not the end, meaning you have no wood but do have an already lit fire, who cares/so what? This has nothing at all to do with moving towards your last condition/combination of lighting a fire. Also, we cover if the fire is already lit with the very next step seen below, anyways. So, that's why this condition/combination/step is completely ignored/left out --- why I have it in this parenthesis block, lol --- I should have this parenthesis block deleted out completely. Notice how this condition/combination/step 's terms are already dealt with: no wood, see above step, and fire is already lit, see below step, and thus we don't need this condition/combination/step at all. #1 and #2 handle this condition/combination/step, so this condition/combination/step is not needed at all. It's completely pointless)

  1. and if the fire is already lit, then you don't need to light the fire, lol, so do this condition/combination/step, next.

  2. which, leaves us with having wood and an unlit fire, which I've already mentioned about at the start with it being this last condition/combination/step to be done: lighting the fire.


does this help with understanding its logic, or no ???


OurJud
04 Nov 2016, 12:50

Not really hege, if I'm perfectly honest. That's just too much info and too deep an explanation for a brain like mine.

Suffice to know that it's best to check what conditions the player HASN'T met and then check which they HAVE.