Jump to content

Array Initialization


Recommended Posts

In C++ I can...
string texts[] = {"Apple", "Banana", "Orange"};
...can I do much the same using an OBSE array?

The objectives are to tidy the code along with reference the strings by numerical index.
I'd rather not have to initialize them line by line as it defeats the purpose.

Link to comment
Share on other sites

You can't do declaration + initialization in a single line, but you can still do:

;declaration
Array_Var texts

;Inside some Begin block
Let texts := ar_List "Apple", "Banana", "Orange"
Link to comment
Share on other sites

Thanks for that, I'd just remembered sv_Split but I would have had to use a delimiter which would be a problem.

Things like # or | could end up in the strings so ar_List will be perfect.

Link to comment
Share on other sites

let MyArray := ar_List 0 "SomeString" 1.1 << returns an Array like MyArry[0] := 0 MyArry[1] := "SomeString" MyArray[2] := 1.1

 

let MyArray := ar_Map 1.3::"SomeString" 1.9::1.1 << returns a Map array like MyArray[1.3] := "SomeString" MyArray[1.9] := 1.1

 

let MyArray := ar_Map "John"::"SomeString" "Mary"::1.1 << returns a Stringmap array like MyArray["John"] := "SomeString" MyArray["Mary"] := 1.1

The values, of course, may be any type, as OBSE does not require that the values be the same type.

 

[EDIT] ooops . . .you guys are fast.

Edited by QQuix
Link to comment
Share on other sites

Darn, stuck again.

EDIT

 

For the sake of this project I decided to go with strings, sv_Split and MessageBoxEx.

 

I'm still very grateful for your support Forli and QQuix.

Your knowledge will help to fix quite a few things I have or will stumbled over.

 

End EDIT

I need to split the arrays back out as MessageBox button labels in several locations.
The idea is to manage arrays at the top of the script and the rest takes care of itself.
I can do this using MessageBoxEx but that, of course, is deprecated.

Link to comment
Share on other sites

You shouldn't care about MessageBoxEx: despite it's deprecated it will never be removed, because some mods use it and the OBSE team can't break the compatibility with them, and because it has some unique features which can't be replicated with normal MessageBox (like the ability to create a dynamic number of button with dynamic text, while vanilla MessageBox only allow a fixed number of buttons with fixed text. Also MessageBoxEx support much bigger messages than MessageBox); for this second reason we already asked to cancel its deprecated" state.

Another deprecated command is sv_Construct, but as MessageBoxEx, it will never be removed for the same reasons.

 

About building the buttons, it's simple:

;declaration:
Array_Var yourArray
String_Var msg
Short i
Short n

;inside some Begin block:
Let msg := "Some message"
Let i := -1
Let n := ar_Size yourArray
While (i += 1) < n
  Let msg += "|" + yourArray[i]
Loop
MessageBoxEx $msg   ;(don't forget to use $ operator to extract the string from the String_Var).
sv_Destruct msg
Edited by forli
Link to comment
Share on other sites

Thanks once again, Forli, code now in place.

 

I not only keep forgetting the ToString ($) but often put "%k" instead of "%z" - there's got to be some language/reason I keep associating k wth char/string but I just can't put my finger on it.

 

All going to plan the mod will be up in next 24 hours.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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