Jump to content

Using non-numeric variables in functions (OBSE)


thefleshvirus

Recommended Posts

There's something with scripting that I haven't been able to figure out and it's driving me crazy. How do you get functions to accept "word" variables?

let x := PlayerRef.GetActorValue speed     ;works
let x := PlayerRef.GetActorValue "speed"     ;works

short y
let y := 4
let x := PlayerRef.GetActorValueC y     ;numeric variables work for for "C" version

string_var y
let y := "speed"
let x := PlayerRef.GetActorValue y     ;doesn't work

I've crawled up and down the OBSE documentation, and tried every combination I can think of to no avail. Being able to use variables for these kind of functions would shrink my scripts in half at least.

Link to comment
Share on other sites

string_var y
let y := "speed"

let x := PlayerRef.GetActorValueC y

- doesn't work either?

 

Aren't the functions working like these:

GetActorValue - by word

GetActorValueC - by code

?

 

By the way, do you (or anyone else) know the way the variables with the words can be compared to find out whenever they are equal? I had a problems with that.

Here is an example. Suppose, I have this:

 

string_var one
string_var two

let one := "Thamriel"
let two := ThamrielRef.Getname

- is there a function exists to compare the words for their equality and which provides 1 in case if they are? I tried something, but I got 1 only in case if

let one := two

or

let one := "Thamriel"

let two := "Thamriel"

which obviously pointless.

Edited by Stealth21
Link to comment
Share on other sites

Functions that take numbers as arguments allow variables no problem. I can put the AV code inside of a short/long/int/float, and the function will accept it. That doesn't seem to be true for functions which take characters as arguments. I'm wondering if there is a way to use string_var for this, or perhaps there is another variable type.

Link to comment
Share on other sites

let x := PlayerRef.GetActorValueC y

- doesn't work either?

Oops, just realized after your post what a useless post I wrote))

 

How about that?

short x
string_var y
short z
short equality

set equality to -2 ; or else it is initialized as zero
let y := "speed"
set equality to ( sv_Compare "speed" y )
if ( equality == 0 )
   set z to 4
   let x := Player.GetActorValueC z
endif
Edited by Stealth21
Link to comment
Share on other sites

The older functions still don't know what a "string_var" is and expect a "string" as input parameter.

However, there's the handy "$" operator, which can be used to make them think the string_var is a string.

 

string_var y
let y := "speed"
let x := PlayerRef.GetActorValue $y     ;should work now
Link to comment
Share on other sites

Why would you want to use a string as an integer value? The game already have speed as a environment variable, so why not just use them as they are?

 

Also be very careful when you use string variables because they will cause bloats if you change their values if you do not sv_deconstruct them so that is an other reason why not use strings really. Be as restrictive with strings as possible and only use them when there is no other options and make sure you destroy them as soon as they have been used. If you do not, the OBSE save file will store the all and grow infinitely.

 

If a function handle strings then they handle them and if they do not, then it will not work. Lets see what types of variables that are involved in GetActorValueC

 

 

 

GetActorValueC - returns the actor value specified by the actor value code
(actorValue:int) reference.GetActorValueC actorValueCode:int
(actorValue:int) reference.GetAVC actorValueCode:int

 

Integer, Reference, Integer

 

There is no point to use strings here at all and if you want to present the value in a Messagebox, just do it like this:

short ValueSpeed

Set ValueSpeed to TargetRef.GetAV speed
MessageBox "Speed = %.0f", ValueSpeed

I use the old set here instead of the OBSE let. Theres no need to complicate it more than this if you do not have a very very god argument or explanation why really. What ye wanna do by the way?

Edited by Pellape
Link to comment
Share on other sites

I have been thinking about this...

 

Lets see what the difference is between Speed and "Speed"

 

We start with the simple one: Speed holds the value of speed for each actor and here is a complete list of all actorvalues that we can get with getav.

 

"Speed" is a string containing 5 letters, s, p, e, e, d and the value of those 5 letters combined could be the combined keycodes or rather ASCI-Codes.

 

Comparing strings could be done with eval if you wanna do that:

if eval ( "Speed" == "Strength" )

...or whatever strings you wanna compare but there is other more complex ways of comparing each specific letter in a string with another string...

 

Well the thing is that strings are nothing but a bunch of letters in a row.

Let Mystring := "A couple of letters"
MessageEX $Mystring

Will print out: A couple of letters

Edited by Pellape
Link to comment
Share on other sites

there is other more complex ways of comparing each specific letter in a string with another string...

Can you, please, share me an example of your aspect? And how to go through the word and obtain the ascii values from each character it has if you know and care to share with.

 

Here is the challenge I have:

string_var one
string_var two
short equality

let one := "Thamriel"
let two := ThamrielRef.Getname
set equality to -2
set equality to ( sv_Compare one two )
MessageBoxEX "%.0f %z %z" equality one two

- the output of that MessageBoxEX is "-1 Thamriel Thamriel".

So, as you can see, the names are equal, but as system can 'see', they are not.

Edited by Stealth21
Link to comment
Share on other sites

Thats odd. You could try the eval instead of sv_compare and see what happens maybe as eval came first in OBSE 1.7 and sv_compare in 1.6?

If eval ($one == $Two )
	Set equality to 1
Else 
	Set equality to 0
Endif

I am not sure we need the $ sign here so try with and without and do not forget to end it all with

sv_Destruct one
sv_Destruct two

The more complex way is to get every letter out of the string, one by one, but that requires that you want the string to be known.

 

Lets take the first letter T and then the h and check them

if ( sv_Find "T" One 0 1 == 1 )
	Message "The first letter in One is T"
Else
	Message "The first letter in One is not T"
Endif

if ( sv_Find "h" One 1 1 == 1 )
	Message "The second letter in One is h"
Else
	Message "The second letter in One is not h"
Endif

This way is very tedious for sure but it works. I use it when I wanna check what the player is typing in a messagebox with GetInputText, where only 2 letters and numbers should be written, nothing else, so if the player types wrong stuff, they will get a messagebox with instructions.

 

Many of the sv_ commands got obsolete from OBSE 1.7 and forward.

 

If the 2 strings are still not equal you could try to get the values out of the strings:

short StringValue

Let Stringvalue := eval $One
message "One has the value %.0f", StringValue

Let Stringvalue := eval $Two
message "Two has the value  %.0f", StringValue

Edited by Pellape
Link to comment
Share on other sites

  • Recently Browsing   0 members

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