Dumber downed variable types.

Post » Sat Oct 29, 2016 2:46 pm

I have been reading Morrowind Scripting for Dummies but I don't understand page 27. On page 27 of the 9th edition it talks about variable types, long, short and float. I don't get it I don't understand what is meant by these variables and the integers. Could someone dumb this down for me and give me some simple examples of how each of these are used and what makes them different.
User avatar
+++CAZZY
 
Posts: 3403
Joined: Wed Sep 13, 2006 1:04 pm

Post » Sat Oct 29, 2016 7:58 am

They are the minimum / maximum values that can be stored in variables of the respective type.



Short: -32768 to 32767
Long: -2147483648 to 2147483647
Float: -3.4*10**38 to 3.4*10**38

If in either direction you exceed the listed values, the variable will "wrap" around to the other end.



set var to 32767
MessageBox "var = %g" var
; shows "var = 32767"

set var to ( var + 1 )
MessageBox "var = %g" var
; shows "var = -32768"


Note: If you want fractions then you must use floats. Storing "1.5" into a long or short would just result in "1" (everything after the decimal is truncated).

User avatar
Bird
 
Posts: 3492
Joined: Fri Nov 30, 2007 12:45 am

Post » Sat Oct 29, 2016 2:57 am

Basically to store an integer like 1 in a computer, you need all bunch of ram. Think of it like this:



long x = 1


"0000000001"



But if you know the limits of your variable, that it will only track to max 30 for example then you can optimize it like this:



short x = 1


"00001"



Then there is floats, when you know you will need fractions.



So select the best fit for each variable.

User avatar
LADONA
 
Posts: 3290
Joined: Wed Aug 15, 2007 3:52 am

Post » Sat Oct 29, 2016 10:12 am

Okay. I think I have a better understanding of variable types. Floats are for fractions. And long and short are for long number values and shorter number values.


What are some examples of these variable types in a script and in the game world?
User avatar
QuinDINGDONGcey
 
Posts: 3369
Joined: Mon Jul 23, 2007 4:11 pm

Post » Sat Oct 29, 2016 12:31 am

Try studying some https://www.scribd.com/doc/7007668/Morrowind-Scripting-for-Dummies-9 script examples/explanation. If you still can't understand variables, scripting is not for you


[EDIT]You can still try to copy/paste/assemble already existing/working script snippets from here and there, but this will not work much if you don't really understand the logic


[EDIT2]to ease studying scripts in Morrowind.esm, you could try right click Morrowind.esm in Mash, export\scripts so you have a unique .txt file with all the scripts and see how variables are used everywhere at a glance

User avatar
phillip crookes
 
Posts: 3420
Joined: Wed Jun 27, 2007 1:39 pm


Return to III - Morrowind