Skip to content

Question About Game Crash

The game only started crashing after writing this heartbeat script. Two NPC's are attacking one another whilst spouting obscenities -
void main()
{
    int nDie = d20();
    if (nDie >= 10)
    {
        switch (d3())
        {
        case 1: AssignCommand(OBJECT_SELF, SpeakString("I'll bleed you dry Crevek!")); break;
        case 2: AssignCommand(OBJECT_SELF, SpeakString("I'll feed your body to the shadows...!")); break;
        case 3: AssignCommand(OBJECT_SELF, SpeakString("Feel the cold steel of my knife...!")); break;
        }
    }
}

I don't know why the game crashes to the desktop when this or these scripts runs?

Second hearbeat script -
int nDie = d20();
    if (nDie >= 10)
    {
        switch (d3())
        {
        case 1: AssignCommand(OBJECT_SELF, SpeakString("Your life belongs to me now!")); break;
        case 2: AssignCommand(OBJECT_SELF, SpeakString("I'll crush your skull to dust...!")); break;
        case 3: AssignCommand(OBJECT_SELF, SpeakString("May the dead feast on your soul!")); break;
        }
    }
}

Comments

  • ForSeriousForSerious Member Posts: 466
    I'm guessing you have void main() in the second, just not shown here?
  • ZephiriusZephirius Member Posts: 419
    Yeah. It just started working again for some reason ForSerious. No more crashes. I'll just chalk it up to a ghost in my machine for now... :)
  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited June 2022
    If you get a crash it can sometimes be helpful to look at the log files found in the logs folder with the user content folders.

    Looking at your code, nothing jumps out as being wrong or liable to cause a crash. Personally I would change 1 little part of it but that is just a personal thing. I would change -
        int nDie = d20();
        if (nDie >= 10)
    
    to -
        int nDie = d2() - 1;
        if (nDie)
    

    which if d2() (i.e. a 2 sided die) works as I think it should means that nDie will either equate to TRUE (1) or FALSE (0).

    TR
  • ZephiriusZephirius Member Posts: 419
    Yeah - there was nothing in the log that I could glean from it. Thanks for the scripting advice. I swear I'll start reading those tutorials soon.
  • TerrorbleTerrorble Member Posts: 179
    Instead of AssignCommand(SpeakString()). Try just SpeakString() or AssignCommand(ActionSpeakString()).
    I have instances of these working on my NPCs.

    This may not apply to this situation but I use a GetIsInCombat() check and GetDistanceBetween(oNPC,oPlayer) < 10.0 or something so the NPCs don't spout off their lines when they shouldn't or when there isn't a player close enough to notice any of it.
  • ProlericProleric Member Posts: 1,316
    The d3() cases are 0, 1 and 2, not 1-3, but I doubt whether that explains the crashes.
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    Proleric wrote: »
    The d3() cases are 0, 1 and 2, not 1-3, but I doubt whether that explains the crashes.

    I just tested this and unless I am missing something, d3() cases are 1, 2 or 3 and Random(3) cases are 0,1 or 2.

    I use a lot of d(3) for my random property items so I wanted to make sure I didn't have to go back and change all of them.
Sign In or Register to comment.