Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get value from stringMap by variable #191

Closed
EdMSL opened this issue Dec 6, 2022 · 14 comments
Closed

Get value from stringMap by variable #191

EdMSL opened this issue Dec 6, 2022 · 14 comments

Comments

@EdMSL
Copy link

EdMSL commented Dec 6, 2022

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
Copy link
Owner

llde commented Dec 6, 2022

what about using $stingVar in the map bracket?

@EdMSL
Copy link
Author

EdMSL commented Dec 7, 2022

It works, thanks

@EdMSL EdMSL closed this as completed Dec 7, 2022
@EdMSL
Copy link
Author

EdMSL commented Dec 7, 2022

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

@EdMSL EdMSL reopened this Dec 7, 2022
@katawful
Copy link

katawful commented Dec 7, 2022

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
Copy link
Author

EdMSL commented Dec 7, 2022

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
Copy link

katawful commented Dec 7, 2022

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
Copy link
Author

EdMSL commented Dec 7, 2022

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
Copy link

katawful commented Dec 7, 2022

MyQuest isn't a variable

@EdMSL
Copy link
Author

EdMSL commented Dec 7, 2022

What is MyQuest ? Is this a Reference?

@katawful
Copy link

katawful commented Dec 7, 2022

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
Copy link
Author

EdMSL commented Dec 7, 2022

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
Copy link

katawful commented Dec 7, 2022

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

@EdMSL EdMSL closed this as completed Dec 7, 2022
@Forlini91
Copy link

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
Copy link
Author

EdMSL commented Dec 10, 2022

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants