Open main menu

UESPWiki β

Morrowind Mod talk:Scripting Pitfalls

Here's where we chat/argue about what goes on the page...

Style and ContentEdit

Here's some rules/suggestions for what goes in this article and how it should be formatted.

  • Sections should be specifically pitfalls -- i.e., common or unexpected problems.
  • Sections should also be fairly short. A short description of the problem and (preferably!) a solution. If more background info is required, then that should probably go into a separate background article.
  • Problems with functions should be reported first on the description page for that that function, and then (maybe) echoed here.

Content QuestionsEdit

Small note about:

if ( object_ID.variable == 1 ) ;--BAD!

I think this syntax is not bad ( at least, it's widely used with NPCs by Bethesda )

abot

Agreed. I noted that too, but haven't had time to edit the page. Feel free. You might also note:

  • That isn't true for global scripts. I.e., you can set the variables of global scripts from outside the global scripts, but you can't read those variables at all from outside. (No error, but the attempt to read always returns 0.)
  • GhanBuriGhan notes that you can access do external variables of object scripts in some ways, but not in other ways. But I don't know the details off hand.

BTW, when editing, use the "Show Preview" button until you've got it right. Then us "Save Page". (Each time you save a page, the page gets saved to the database, as you can see from the history tab.)

Wrye 14:27, 24 Oct 2005 (EDT)

another note for the ====Comparison Operator==== section: maybe

while ( Count !=20 )  ;GOOD

was intended to be

while ( Count != 20 )  ;GOOD

abot

Content Questions IIEdit

I noticed in the CS if you start a variable a number you get error messages on compile

             e.g.  Short 1Short  Float 1Float  <- bad
             Short Short1  Float Float1  <-Good

also if you name objects with a numeral you need quotes if not you don't

1NPC->AIFollow   <- Bad  
 "1NPC"->AIFollow  <- OK
AA1NCP->AIFollow  <- OK   so really its much easier 

Also if A Global Script is called by a Script attached to an NCP or Dialogue the "Fix" is not needed so if you have lots of NCP's its better to leave out the fix

NCP1+[General NCP Script] StartScript Do Something (no fix needed) auto fixed to NCP1

NCP1 Dialogue StartScript Do Something (no fix needed)

I have tested this with a remove armour script - only 1 script for 3 NCP's ..

So do you want me to write a section ?

--ExclusiveOR 05:43, 15 August 2006 (EDT)

First, remember that this article is about scripting pitfalls, things that work in an unexpected way and can catch the uninformed scripter. I don't see anything here worth keeping. Specifically:
  • I think that most scripters know that it's a bad idea to start object/variables names with numbers, so this doesn't qualify as a pitfall. It might however be worth recording on the Morrowind Mod:Id Standards (which is really, really old).
  • The stuff about fix from a dialog is well known. All scripts except startup scripts have context, which is inherited from the script (or object) that launches it. The fix is just used to override the default context.
So, there's nothing sufficiently "pitfallish" enough to be recorded here. --Wrye 20:49, 16 August 2006 (EDT)

ok --ExclusiveOR 10:06, 3 September 2006 (EDT)

Really odd sentenceEdit

Just came across this sentence: "GetSkill will of course only work on NPCs". My interpretation after the initial WTF was that I think it means it won't work on inanimate objects. But since I was looking for info on using it on the Player I was quite shocked to see a sentence like this obviously written by an idiot. --FMan | Talk (contribs) 20:28, 4 March 2007 (EST)

FYI, the person you just insulted is Lurlock. The sentence is fine and the meaning is clear within the context -- hijacking miscellaneous information storage to use for storing variables. Also, FYI, several mods have hijacked these variables in just this way. The note about the limitations is useful -- and yes, people oftentimes miss the obvious, so it does not hurt to point it out. --Wrye 23:33, 5 March 2007 (EST)

What Pitfall Is This ?Edit

begin DawnDuskSwordScript 



if (gamehour == 6.00) 

; adds the Sword of Dawn if it's 6:00 AM
        player->AddItem "THA_wep_azura_01" 1 

elseif (gamehour >= 6.00) 
        MessageBox, The amulet has not had any effect, however it is an artifact of Azura, as such it may be wise to wait until dusk or dawn, if it still does nothing the man that sold it cheated me, however he is unfortunately long gone in any case.

if (gamehour <= 18.00) 
        player ->RemoveItem "THA_wep_azura_01" 1
        player->AddItem "THA_wep_azura_02" 1

else
        MessageBox, The amulet has not had any effect, however it is an artifact of Azura, as such it may be wise to wait until dusk or dawn, if it still does nothing the man that sold it cheated me, however he is unfortunately long gone in any case.

endif 

end DawnDuskSwordScript

With this script it doesn't recognize player or gamehour why ?--TheAlbinoOrc 19:24, 7 June 2010 (UTC)

While I'm no expert on Morrowind scripting, it's possible that they're case-sensitive. Try Player and GameHour and see if those make a difference. Rpeh's also familiar with scripting, I believe. You may want to ask him. Robin HoodTalk 23:40, 9 June 2010 (UTC)


Both gamehour and player probably work, script logic and syntax are screwed. A possible (not tested in game) implementation below
begin DawnDuskSwordScript 

short daytime
short lastdaytime
short state

if ( MenuMode )
        return
endif

if ( gamehour > 6 )
        if ( gamehour < 18 )
                set daytime to 1
        else
                set daytime to 0
        endif
else
        set daytime to 0
endif

if ( daytime == lastdaytime )
        return
endif
set lastdaytime to daytime

if ( state == 0 )
        if ( daytime )
                player->AddItem "THA_wep_azura_01" 1
                set state to 1
        endif
        return
endif

if ( state == 1 )
        if ( daytime )
                return
        endif
        while ( player->GetItemCount "THA_wep_azura_01" > 0 )
                player->RemoveItem "THA_wep_azura_01" 1
        endwhile
        player->AddItem "THA_wep_azura_02" 1
        set state to 2
        return
endif

if ( daytime )
        while ( player->GetItemCount "THA_wep_azura_02" > 0 )
                player->RemoveItem "THA_wep_azura_02" 1
        endwhile
        player->AddItem "THA_wep_azura_01" 1
        set state to 1
endif

end

- Abot (talk) 07:05, 18 April 2013 (GMT)

Return to "Scripting Pitfalls" page.