Jump to content

Odd Scripting Problem - Help Sought!


DocClox

Recommended Posts

Posted

I want to set up a library quest that initialises, and then softloads the main quest from another mod. It's a fairly common idiom.

 

The trouble is that while the library quest reports that it loads the mod OK, another script trying to use that reference gets None back.

 

The library quest that looks a bit like this:

scriptname Libby extends quest
;
; Library script
;

ExternalQuestScript property q auto

event oninit()
    if Game.GetModFromFile("ExternalMod.esm") == 255
        return
    endif
    q = Quest.GetQuest("External Quest")
    debug.notification("q = " + q)
endevent

ExternalQuestScript function get_q()
    debug.notification("get_q called")
    debug.notification("returning " + q)
    return q
EndFunction

 

When it starts, I see the "Q = Q[..." I'd expect to see when I print a quest object to the screen. Definitely not null.

 

The client script that looks like this:

 

Scriptname calling_script extends Whatever

Libby property lib auto

function test1()
    ExternalQuestScript q = lib.get_q()
    if q == None
        debug.notification("No Q!")
    else
        debug.notification("I got Q babe")        
    endif
endfunction

function test2()
    if lib.q == None
        debug.notification("No Q!")
    else
        debug.notification("I got Q babe")        
    endif
endfunction

Now, both of those functions print "No Q". WHich is odd because I've seen the library quest just report getting a value for the script.

 

Weirder still, the get_q() method in the library doesn't seem to be called at all, or at least its debug messages never get printed.

 

Any ideas, anyone?

 

Posted

Your problem is that you are trying to convert a Qest to an ExternalQuestSript. It gets coverted to None.

 

 

Replace

ExternalQuestScript property q auto

ExternalQuestScript function get_q()
    debug.notification("get_q called")
    debug.notification("returning " + q)
    return q
EndFunction

With

Quest property q auto

Quest function get_q()
    return q
EndFunction
Posted
1 hour ago, DocClox said:

Any ideas, anyone?

I think you have a problem caused by the incorrect type of the declarations of the variables.

 

1 hour ago, DocClox said:

ExternalQuestScript property q auto

You have defined q as ExternalQuestScript and seems that ExternalQuestScript is a script that you have created and probably not extend any.

 

When you put inside the variable q the result of Quest.GetQuest("External Quest") the game must make some type conversions for show the message debug.notification("q = " + q) 

But when you try access that variable from other script the TYPE of the variable not match the TYPE of the object that contains and probably the game can not make dinamically the type conversion.

 

SOLUTION: Define the variable q as Quest because must have a Quest object.

If you really need the script ExternalQuestScript extend is as Quest or Form.

Posted

Actually, I think it was just a script that needed recompilation. I just rebuilt everything and it's now working. Or at least it's breaking somewhere where I haven't yet noticed.

 

This was the actual library file (or relevant parts thereof)

 

scriptname docbook_quest_scr extends quest

formlist property sttf_slaves auto
int property beat_freq = 10 auto
slaFrameworkScr Property slaf  Auto
PAHCore property pah auto

event OnInit()
        debug.notification("poke")
        poke()
endevent

PAHCore function get_pah()
        debug.notification("Pah requested")
        debug.notification("returning " + pah)
        return pah
endfunction

function poke()
        if Game.GetMOdByName("paradise_halls.esm") != 225
                pah = Quest.GetQuest("PAH") as PAHCore
                debug.notification("pah = " + pah)
        endif
        debug.notification("register: " + beat_freq)
        RegisterForSingleUpdate(beat_freq)
endfunction

And I was calling it thus:

 

        PAHCore pah = mq.get_pah()
        debug.notification("pah = " + pah)
        if pah == None
                debug.notification("*** no PAH - setting new name to " + new_name)
                t.setDisplayName(new_name, true)
        else
                debug.notification("PAH Found - using PAHSlave to set name to " + new_name)
                pah.getslave(t).setDisplayName(new_name)
        endif

 

Posted
3 hours ago, DocClox said:

Actually, I think it was just a script that needed recompilation. I just rebuilt everything and it's now working. Or at least it's breaking somewhere where I haven't yet noticed.

 

This was the actual library file (or relevant parts thereof)

 

And I was calling it thus:

 

 

Now works because you are defining your property as PAHCore and PAHCore extends Quest and the TYPE of the variables are correct and of course works.

Quote

Scriptname PAHCore extends Quest Conditional

 

Posted
29 minutes ago, GenioMaestro said:

Now works because you are defining your property as PAHCore and PAHCore extends Quest and the TYPE of the variables are correct and of course works.

Thanks for your help.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...