Using a reference as an integer

Post » Sat Feb 19, 2011 12:42 am

Is there any way to use an object reference as an integer that you can perform math on?

For example, say I want to modify a given copy of an item on the ground based on a modulus of its refID; if I do:
int myvar
ref objectrefid
set myvar to objectrefid % 3

or even just:
set myvar to objectrefid

in either case, myvar is just 0.

Relating to this, is comparing a refID to 0 a safe way to determine if the reference is empty?

Queue
User avatar
tiffany Royal
 
Posts: 3340
Joined: Mon Dec 25, 2006 1:48 pm

Post » Sat Feb 19, 2011 3:13 am

Is there any way to use an object reference as an integer that you can perform math on?


No, but from your example you could use some other semi-random property.
Maybe use GetPos to get the posx and posy (floats), then...

100* (posx + posy) %3

Relating to this, is comparing a refID to 0 a safe way to determine if the reference is empty?


Yup.

Or just 'if rMyref' to start the block for a defined ref.
User avatar
Sista Sila
 
Posts: 3381
Joined: Fri Mar 30, 2007 12:25 pm

Post » Sat Feb 19, 2011 12:46 am

Darn.

Thanks, though, and I appreciate the idea for an alternative to snagging a different property; that hadn't crossed my mind.

I don't suppose anyone could explain why comparing to 0 (or like you said, just doing ''if refid'') works, but comparing it to any other specific value doesn't?

Queue
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Sat Feb 19, 2011 5:18 am

The short list of ref manipulation can be seen here: http://geck.gamesas.com/index.php/Reference_variables.
That didn't stop me also experimenting with casting int's to ref's and vice versa though :)

I think 'myref == 0' is a special case.
Assigning 0 is a valid way to clear a ref, so 0 probably acts as a ref in that context.
If the rhs was +ve then it may do an integer comparison. (so the ref will always be 0 when cast to int)
My guess is irrelevant though as it we couldn't change that even if we wanted to.


I was experimenting with a view of adding mod compatibility without having to include the foriegn mod as a dependency.
ie. We can look at some foreign mods FormID's, and if we could use casting then we could calculate the ID on-the-fly with NVSE.
Adding ref2int would be fairly straightforward I think, (just clone GetModIndex without the bitshift).
I then started to write how I'd use the new function in GECK scripting, and decided that just that one function would lead to kludgy code if there were many ref's to calc.
So had a little brainstorming new functions with a view of submitting an nvse patch eventually... but that probably will never happen. I'd forgotten all about it until this thread lol.

Spoiler

int iModBaseint iItemref rObj;Adding a single itemif IsModLoaded "OtherMod.esp"	set iModBase to GetModIndex "OtherMod.esp"	set iModBase to LeftShift iModBase 24	set iItem to LogicalOr iModebase 123	set rObj to Int2Ref iItem	if IsFormValid rObj		if IsReference rObj == 0			ListAddForm MyForm rObj		endif	endifendif;Adding a few itemsif IsModLoaded "OtherMod.esp"	set iModBase to GetModIndex "OtherMod.esp"	set iModBase to LeftShift iModBase 24	set iItem to LogicalOr iModebase 123	set rObj to Int2Ref iItem	rObj.ListAddRef TempForm	set iItem to LogicalOr iModebase 456	set rObj to Int2Ref iItem	rObj.ListAddRef TempForm	Label 1	if ListGetCount TempForm		set rObj to ListRemoveNth TempForm 0		if IsFormValid rObj			if IsReference rObj == 0				ListAddForm MyForm rObj			endif		endif		Goto 1	endifendif;Adding *lots* of items (this is where Ref2Int would be handy)if IsModLoaded "OtherMod.esp"	set iModBase to GetModIndex "OtherMod.esp"	set iModBase to LeftShift iModBase 24	set rObj to Int2Ref 123	rObj.ListAddRef TempForm	set rObj to Int2Ref 456	rObj.ListAddRef TempForm	set rObj to Int2Ref 789	rObj.ListAddRef TempForm	Label 1	if ListGetCount TempForm		set rObj to ListRemoveNth TempForm 0		set iItem to Ref2Int rObj		set iItem to LogicalOr iItem iModebase		set rObj to Int2Ref iItem		if IsFormValid rObj			if IsReference rObj == 0				ListAddForm MyForm rObj			endif		endif		Goto 1	endifendif;Adding *lots* of items (this is where ListAddInt & ListRemoveNthInt would be handy)if IsModLoaded "OtherMod.esp"	set iModBase to GetModIndex "OtherMod.esp"	set iModBase to LeftShift iModBase 24	ListAddInt TempForm 123	ListAddInt TempForm 456	ListAddInt TempForm 789	Label 1	if ListGetCount TempForm		set iItem to ListRemoveNthInt TempForm 0		set iItem to LogicalOr iItem iModebase		set rObj to Int2Ref iItem		if IsFormValid rObj			if IsReference rObj == 0				ListAddForm MyForm rObj			endif		endif		Goto 1	endifendif



I don't know if adding int's to formlists is feasable but there have been dozens of times I wished for numerical arrays while coding.
User avatar
liz barnes
 
Posts: 3387
Joined: Tue Oct 31, 2006 4:10 am

Post » Sat Feb 19, 2011 3:49 am

Honestly, accounting for mods and DLCs without being dependent on them was half of why I asked. I wound up with a kludgey solution for a specific situation I wanted to cover for (the Gecko-Backed armors from Honest Hearts). I identify those 4 armors instead by using GetModIndex and GetSourceModIndex, if that matches then use the weight of the armor to determine what it is (luckily the 4 Gecko-Backed armors have unique weights among the Honest Hearts armors). After identifying them I then use SwapTexture to slap a gecko texture onto them (which is a can of worms all on its own... is there an easy way to find the name of the parts of a model for retexturing? because I just opened up the meshes in a hex editor to get the part names and used trial-and-error to figure out which label was related to which part of the model).

And even then, that was unrelated to me wanting to use a modulus of an item's refid, but ultimately using the item's weight was still the result of your suggestion to look elsewhere for identifying characteristics.

I come from an assembly programming background, so variable types make no sense to me... if you mess up, it's your own fault.

Queue
User avatar
Romy Welsch
 
Posts: 3329
Joined: Wed Apr 25, 2007 10:36 pm

Post » Sat Feb 19, 2011 8:17 am

Ooh, smart thinking on the weight idea.

I've posted a request in the nvse thread to hopefuly get a basic ref2int function added if poss.
User avatar
Brιonα Renae
 
Posts: 3430
Joined: Mon Oct 22, 2007 3:10 am


Return to Fallout: New Vegas