Jump to content

GECK - Unable to compare string variable


FiftyTifty

Recommended Posts

Hullo lads, got a wee conundrum.

 

I've a script that is attached to a perk entry, of the ol' "entry point" type. It checks the name of an activated actor. If it has "Protectron" or some variant of that in it's name, that is dead, and that respawns, replace it with me own version.

 

Seems the GECK doesn't like me comparing strings, however. Throws me an error at line 9, saying "Syntax Error: Unknown command 'Protectron'".

 

Here's me script:

 

 

 

 

ref TheRobot
set TheRobot to GetSelf
string_var TheRobotName
let TheRobotName := $TheRobot

if GetRespawn TheRobot


    if TheRobotName == "Protectron"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk1"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk2"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk3"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk4"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk5"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif
    
    elseif TheRobotName == "Protectron Mk6"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif

endif

 

 

 

Why the bloomin' heck does it not compile?

Link to comment
Share on other sites

You shouldn't close every elseif with an endif, but only at the very end of the structure:

if ...

elseif ...

elseif ...

elseif ...

endif

 

Also, if you're comparing strings, you should use 'eval'.

Edited by DoctaSax
Link to comment
Share on other sites

You shouldn't close every elseif with an endif, but only at the very end of the structure:

if ...

elseif ...

elseif ...

elseif ...

endif

 

Also, if you're comparing strings, you should use 'eval'.

 

Good tips. Here's what the script looks like now:

 

 

 

 

ref TheRobot
set TheRobot to GetSelf
string_var TheRobotName
let TheRobotName := $TheRobot

if GetRespawn TheRobot


    if eval TheRobotName == "Protectron"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk1"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk2"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk3"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk4"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk5"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
    
    elseif eval TheRobotName == "Protectron Mk6"

        TheRobot.PlaceAtMe AAAFyTyRepairedProtectron
        TheRobot.Disable
        TheRobot.MarkForDelete
        
    endif

endif

 

 

 

However, it seems that New Vegas doesn't like me using the Let command. It throws up this error in the console:

 

"An expression failed to evaluate to a valid result

 

File:FalloutNV.esm Offset: 0x000F Command: Let"

 

It should just work, but...

Link to comment
Share on other sites

NVSE up to date? Older versions didn't have 'let'.

I think $TheRobot would make a string of hex values of the Robot's formID, not the name of the robot. How about



let TheRobotName := TheRobot.GetName

Link to comment
Share on other sites

 

NVSE up to date? Older versions didn't have 'let'.
I think $TheRobot would make a string of hex values of the Robot's formID, not the name of the robot. How about
let TheRobotName := TheRobot.GetName

 

Aye, me NVSE is up to date. Even usin' the latest beta version. I'll give yer wee recommendation a lil' go around.

 

Nah, just returns the same error, but with the offset being 0x0001, and the command being "Unkown". Bah, nae idea why this is cocking up so bad.

 

Good news, is that I've got the packages and dialogue all working nice and dandy, for the replacement Protectron npcs that the player should spawn. Just need to get this perk script fixed up.

 

 

Edit: I'll link me mod, in case any of you lads fancy having a go with it, see what's what. All me added records begin with AAAFyTy, so 'tis easy to find me records; just chuck FyTy in the object filter. The script in question is attached to a perk.

 

http://www.mediafire.com/download/11dvbjj8etim94i/EZRobits.7z

Edited by FiftyTifty
Link to comment
Share on other sites

My testing seems to indicate that the activate perk entry script does not allow you to define variables inside. Any change made to them will not stick and the variable will continue to have a default value, which is why the let command fails, as there is no string to retrieve.

 

My apologies that I didn't catch this in my response to the previous thread of yours.

 

To fix it, I would move the script to a user defined function (UDF) that you call from the perk script. You can make use of the Call function's ability to be called on references. For example, in the perk script you simply have this:

call ReplaceRobotUDF

The activated reference will be the calling reference of the call function. The calling reference will be passed to the UDF, allowing you to call reference functions on it with implicit syntax, so you can use GetSelf to store it in a ref variable.

 

Here's what the UDF should look like. It's only for demonstration purposes, you can fill in the rest of the script yourself. It should be saved as an object script.

scriptName ReplaceRobotUDF
ref obj

begin function{}
    let obj := getSelf
end
Edited by Ladez
Link to comment
Share on other sites

 

My testing seems to indicate that the activate perk entry script does not allow you to define variables inside. Any change made to them will not stick and the variable will continue to have a default value, which is why the let command fails, as there is no string to retrieve.

 

My apologies that I didn't catch this in my response to the previous thread of yours.

 

To fix it, I would move the script to a user defined function (UDF) that you call from the perk script. You can make use of the Call function's ability to be called on references. For example, in the perk script you simply have this:

call ReplaceRobotUDF

The activated reference will be the calling reference of the call function. The calling reference will be passed to the UDF, allowing you to call reference functions on it with implicit syntax, so you can use GetSelf to store it in a ref variable.

 

Here's what the UDF should look like. It's only for demonstration purposes, you can fill in the rest of the script yourself. It should be saved as an object script.

scriptName ReplaceRobotUDF
ref obj

begin function{}
    let obj := getSelf
end

 

It just works. Daaayum dude, you're good at this scripting stuff. And bloody Bethesda made sure ta keep their engine as inconsistent as usual. Pah.

 

Right, me new goal, now that the core works, is to figure out how to make Protectrons haul ass. Guys waddle like penguins with ingrown toenails.

Link to comment
Share on other sites

Don't declare variables in anything except quest, function or object scripts unless you want bad crap happening later on.

 

you can also use the this command instead of getself so GECK doesn't complain about it.

 

 

 
scriptName ReplaceRobotUDF

ref rRef

begin function { }
    let rRef := this
end
 
Link to comment
Share on other sites

  • Recently Browsing   0 members

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