Talk:Declaring variables

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

--Mrflippy 18:42, 13 April 2006 (EDT): What are the restrictions on variable names? I received (seemingly) inconsistent errors when I tried to start a variable name with an underscore. It seemed to let me do that with some variables, but with others it wouldn't.

--Mrflippy 00:21, 30 April 2006 (EDT): How are variables scoped? If I declare a variable in an if block, is that variable accessible outside of the if block? If I declare a variable in an OnActivate block, is that variable accessible in the GameMode block?

--JOG 08:48, 1 May 2006 (EDT) Variables are always accessible in the whole script, sometimes it's nicer to put the variables within or above the block where they're used, but it makes no difference

--MaXiMiUS 22:54, 28 May 2006 (EDT) How was I able to use int VarName? The script runs fine and saves as well, yet int is undocumented :/

--Dragoon Wraith 23:50, 28 May 2006 (EDT): Perhaps to alleviate programmer headache, they made int==short?

Floating-point range[edit source]

It might be possible to use both +0 and -0, as well as +∞, -∞ and NaN from the IEEE 754 floating-point standard. Anybody tried it yet? --Khadir 12:40, 28 June 2006 (EDT)

They're standard 32Bit Floats so $7f800000 should be +∞, yes. You should be able to use the special values within a calculation, but I doubt that Set has any use for them.
Also, a reference-variable doesn't behave like a normal variable (you can not assign a FormId to it, only a reference/ObjectID) and when you view a compiled quest-script, there is not only the 24Byte SLSD-entry but also a 4-Byte SCRV entry that contains the variable's number within the script as second byte (e.g. 00060000 for the 6th variable in the script) this "serial-number" is also within the SLSD-entry, and normal variables consist only of the SLSD entry, so I assume that a reference-variable has need for an additional 16Bit value.--JOG 14:39, 28 June 2006 (EDT)

What are the differences between Short, Long, and Float?[edit source]

Okay, just my interpretation of all this, so correct me if I'm wrong here. :) I've scripted before, I just never really thought to much on these and used whatever seemed appropriate at the time.

Well, as I understand it, there are different situations in which I would want to use either float or short variables... I don't really get the purpose of long, but anyway.

Short is used in instances where you want to affect referenced objects and/or their scripts only on a local scale, while float shares the same name variable with any other objects and their scripts within the specified radius. I would not want to use a short var on an exterior worldspace where there is... say, two gate switches, but reasonably far apart, I should use float if they are for the same gate.

Hehe :D, yes, the article might be able to make good use of some of these examples... If I'm more or less on target here. The Imperial Dragon 23:50, 15 August 2006 (EDT)


A short is a small integer variable (taking only 2 bytes of memory).
A long is a large integer variable (taking 4 bytes of memory).
A float is a floating point variable with, well, a floating point. Also taking 4 bytes of memory.
The normal integer variable in C is a 32Bit integer named "int" so they made this also available.


The variable-type only determines the size and capabilities of the variable, it has absolutely nothing to do with the utilisation.
You use a float when you need a floating point, you use a short when you havce small numbers without decimal places, and a long when you have large numbers without decimal places.
Whether you use short or long doesn't really matter as long as your value is smaller than +/- 32768 (a short can't hold more). Today, the difference between 16Bit integer and 32Bit integer is more a imaginary efficiency thingy. But when you're conditioned to always use the least memory-hungry type you always hesitate to use long (even in Globals where all variable types are stored as float) :-)
JOG 03:37, 16 August 2006 (EDT)
Dragoon Wraith TALK 10:10, 16 August 2006 (EDT): Timeslip and I found that longs are always floats, not just in Global variables. Oblivion does not appear to have a "long" variable, even though it'll compile. And apparently shorts are floats too, at least in the esm/esp/ess file (whether or not they are in game is unknown).
I didn't try int, though. Is it worth trying? A true long variable would save me a lot of headaches.

Yes, alright, then it's the values that are determined by this... I don't know how I came up with the above theory, but anyway. So, only a float can have decimal places, correct? Therefore, that would probably be the better option when getting the location of the player in a dungeon, or the location of anything for that matter.

Short is good for DoOnce and the like.

The Imperial Dragon 14:13, 16 August 2006 (EDT)

Dragoon Wraith TALK 22:51, 16 August 2006 (EDT): I tried Int's, had the same problems as I had with longs. They're all floats.