llde / xOBSE

Oblivion Script extender source
243 stars 35 forks source link

Get value from stringMap by variable #191

Closed EdMSL closed 1 year ago

EdMSL commented 1 year ago

I have a stringMap like this:

Let aaaDBTAMArr := ar_Construct StringMap
Let aaaDBTAMArr["keyone"] := "Value of TakeAllKey"
Let aaaDBTAMArr["keytwo"] := "ExitKey"
Let aaaDBTAMArr["keythree"] := "Messageon"

I can get value of key "keytwo" by command aaaDBTAMArr["keytwo"]. Is there any way to get value of some key by variable?

Let stingVar := "keytwo"
let secondStringVar := aaaDBTAMArr[stingVar]

It doesn't work, neither does aaaDBTAMArr->stingVar.

llde commented 1 year ago

what about using $stingVar in the map bracket?

EdMSL commented 1 year ago

It works, thanks

EdMSL commented 1 year ago

Can I get the value of variable of another quest in a similar way? F.e. there is a variable someVariable on any quest script for quest with name "SomeQuest".

scn SomeQuestScn
short someVariable 
//some other code

and I want to get value of this someVariable variable from my another script. By default we write:

scn MyScript
short myvar
Let myvar := SomeQuest.someVariable 

Is there any way to get value by variable?

Let stingVar := "someVariable "
Let myvar := SomeQuest[$stingVar ] // not works
katawful commented 1 year ago

Quest variables are scoped by itself:

; quest script
scn quest
int i
array_var a
; other script
string_var string
array_var array
let x := quest.a[$string]
let x := array[$quest.i]

They accept all operators as well

EdMSL commented 1 year ago

Yes, but I want to get value of variable from another script by string:

let sting := "a"
let x := quest[$string]
//or
let x := quest["a"]
katawful commented 1 year ago

I'm not sure what you're asking exactly, all quest variables are scoped like so: quest-ref-name.variable-ref-name

If you want to get the value of said quest var by string, you can still stringicize with $

Let x := some_array[$quest.var]

If you want to get the value of a quest array variable you can still do that:

Let x := quest.var[$some_array]
EdMSL commented 1 year ago

This is a quest script for MyQuest:

scn MyQuestScript

short attempts
short doonce

begin MenuMode
    if doonce != 1
        set attempts to 10
        set doonce to 1
    endif
end

This is an another script:

scn GetAttemptsScript

string_var text
short data
short isGetData

begin GameMode
    if isGetData != 1
        // by default we write:
        let data := MyQuest.attempts //data will be 10

        // but I want:
        let text := "attempts"
        let data := MyQuest[$text] //not works
        set isGetData to 1
    endif
end
katawful commented 1 year ago

MyQuest isn't a variable

EdMSL commented 1 year ago

What is MyQuest ? Is this a Reference?

katawful commented 1 year ago

You did let data := MyQuest[$text]

MyQuest is not a variable, and also doesn't seem to be a valid reference either (like a quest reference). You can only subscript or member access array and string variables

EdMSL commented 1 year ago

Ok. You writed: all quest variables are scoped like so: quest-ref-name.variable-ref-name I should to write let quest-ref-name.variable-ref-name := 1 Is there any way to replace variable-ref-name by value of var_string?

var_string x
let x := "some"
let quest-ref-name[$x] := 1 //not works
katawful commented 1 year ago

Quest variables behave like namespaces in other languages (e.g. std::cout in C++, string.format in Lua, etc...). They're a token themselves and work as a whole. There's no other way to access quest variables

You can do $quest.variable to stringicize quest variables as $ operates on the whole of the quest variable. You need to include this all if you want to use $

[] is for subscripting arrays and strings. It is not for anything else

Forlini91 commented 1 year ago

You can use this GetVariable

scn MyQuestScript   ; from questo MyQuest

float myVar
float anotherMyVar
string_var nameOfProperty
float value
...
let nameOfProperty := "myVar"  ; or "anotherMyVar"
let value := GetVariable $nameOfProperty MyQuest
EdMSL commented 1 year ago

Is there something similar to this for setting a quest variable?

P.S. I think I can use RunScriptLine function.