Jump to content

Noesis python code help


Go to solution Solved by Rabatini,

Recommended Posts

  • Engineers
Posted

Hi, can somebody please help me out with this?

i want to use var "RwShapeIndex" from "i loop" in "j loop"

how i can do that if anyone know. Thanks in advance!

	bs.seek(RwShapeIndexTableOffset, NOESEEK_ABS)
	for i in range(0, RwVertexInfoCount):
	    RwUnknown_0 = bs.readUShort()
	    RwUnknown_1 = bs.readUShort()
	    RwShapeIndex = bs.readUShort()

	bs.seek(RwVertexInfoOffset, NOESEEK_ABS)
	for j in range(0, RwVertexInfoCount):
	    Underline = "_"
	    RwShapeInc = j
	    RwShapeIdxNum = "{:04d}".format(RwShapeIndex)
	    RwShapeIndexTmp = str(RwShapeIdxNum)
	    print(RwShapeIndexTmp)

 

  • Engineers
Posted (edited)

If you mean something like that >

RwShapeIdxNum = "{:04d}".format(RwShapeIndex[i])

it doesn't work. I also created initial var RwShapeIndex = []

Saying > 

RwShapeIdxNum = "{:04d}".format(RwShapeIndex[i])
TypeError: 'int' object is not subscriptable

 

Edited by h3x3r
  • Engineers
Posted

yeah, that's the reason I usually don't use python.

There's solutions which say:

Quote

To fix this error, you need to convert the integer to an iterable data type, for example, a string.

but that sounds funny to me.

  • Engineers
Posted

Already tried. No luck... Yeah i like python too... 🙃Anyway thank you for your time.

  • Engineers
  • Solution
Posted

Did you tried Store RwShapeIndex Values in a List?

Somenthing like that?
 

bs.seek(RwShapeIndexTableOffset, NOESEEK_ABS)
rw_shape_indices = []  # Create a list to store RwShapeIndex values
for i in range(0, RwVertexInfoCount):
    RwUnknown_0 = bs.readUShort()
    RwUnknown_1 = bs.readUShort()
    rw_shape_indices.append(bs.readUShort())  # Append to the list

bs.seek(RwVertexInfoOffset, NOESEEK_ABS)
for j in range(0, RwVertexInfoCount):
    Underline = "_"
    RwShapeInc = j
    RwShapeIndex = rw_shape_indices[j] #get the value from the list using the j index.
    RwShapeIdxNum = "{:04d}".format(RwShapeIndex)
    RwShapeIndexTmp = str(RwShapeIdxNum)
    print(RwShapeIndexTmp)

 

  • Like 2
  • Thanks 1
  • Engineers
Posted

That's funny. Isn't rw_shape_indices a list of ints (shorts) while python claims an array of ints not to be subscriptable?

The magic is append - apparently python prefers lists over arrays because these have a fixed size.

  • Engineers
Posted
59 minutes ago, shak-otay said:

That's funny. Isn't rw_shape_indices a list of ints (shorts) while python claims an array of ints not to be subscriptable?

The magic is append - apparently python prefers lists over arrays because these have a fixed size.

Lists are the default go-to dynamic sequence type in Python because of their flexibility.
The append method works naturally on lists, while array.append() requires that the appended value be of the correct type.
Many Python libraries and frameworks default to lists for simplicity.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...