WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-23-2011, 12:20 PM
starlingstm starlingstm is offline
Member
 
Join Date: May 2011
Posts: 19
Exclamation Object not subscriptable

Hello, I am defining a function with with a FOR and IF loop inside to print the position of an object. If the object is correctly placed with before the loop completes, the cooridnates will print along with a mesaage for the next action. If the object isn't place before the loops completes, a message is printed along with the correct coordinates.. The problem I having is an error that reads:

File "C:\Users\Husam\if loop test.py", line 17, in showData
if box_pos[0]==3 and pos[1] == 4.0 and pos[2] == -5.0:
TypeError: 'float' object is not subscriptable

But, if go through and check each box_pos[0] - box_pos[2] individually the loop works. I only get the error when I codes is as follows:


import viz
import vizact
import vizshape
viz.go()

box = vizshape.addBox([1,1,1],splitFaces=True,pos=(3.0,4.0,-5.0))
box_pos = box.getPosition(viz.ABS_GLOBAL)



def showData():
for number in range(5):
for pos in box_pos:
if box_pos [0]== 3.0 and pos[1] == 4.0 and pos[2] == -5.0:
print box_pos, 'The Box is connected properly move to next connection'
else:
print box_pos
vizact.ontimer(3,showData)

Please help!!!
Reply With Quote
  #2  
Old 11-23-2011, 03:12 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The variable pos is not a list, it's a single float value taken from the box_pos list. So you can't refer to an element within it.
Reply With Quote
  #3  
Old 11-29-2011, 10:32 AM
AySz88 AySz88 is offline
Member
 
Join Date: Aug 2011
Posts: 13
Instead of this:
Code:
for pos in box_pos:
    if box_pos [0]== 3.0 and pos[1] == 4.0 and pos[2] == -5.0:
      print box_pos, 'The Box is connected properly move to next connection'
you want something more like this:

Code:
if box_pos[0] == 3.0 and box_pos[1] == 4.0 and box_pos[2] == -5.0:
  print box_pos, 'The Box is connected properly move to next connection'
...

You may also want to compare positions approximately (i.e. "abs(box_pos[0] - 3.0) < 1e-3") to avoid any problems with rounding error.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to render a texture of the transparent object and then blur it whj Vizard 1 09-25-2012 03:15 PM
how to hide 3D virtual object behind real object? Darkmax Vizard 3 05-29-2012 09:39 AM
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
Making an object to appear after other object done animating jaylocco Vizard 2 07-13-2009 06:17 PM
rotate to object jargon Vizard 1 08-08-2005 12:20 PM


All times are GMT -7. The time now is 06:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC