Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

Py4d beginner

Author
Message
  Topic Search Topic Search
kornyclown View Drop Down
Member
Member


Joined: 2012 Mar 19
Online Status: Offline
Posts: 2
Direct Link To This Post Topic: Py4d beginner
    Posted: 2012 Mar 19 at 12:37pm
I started learning Python about 1 year ago, I'm fimiliar with Pythonsyntax and meanwhile with OOP structures as well.
Now I'm trying to get deeper into Py4d so these are my first steps.

I have a very basic problem:

from c4d import gui

gui.QuestionDialog("Do you think I am a dialog?")
if True:
    print ("You are right.\n I am a dialog")
       
else:
    print ("You are wrong.\n I really am a dialog.")

       
Basicly this works but its buggy.
The documentation says the gui.QuestionDialog() pops up a dialog with a "yes" and "no" button and returns True if the user answered Yes, otherwise False.
But in my case I get True either way, at least I get the print from the True value either way. No matter if click "yes" or "no".

Why?
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2012 Mar 19 at 12:49pm
Hi kornyclown,

You need to assign the return-value of the function to a variable and test that variable in the
if-clause. Checking for if True: will always succeed because True actually is True.

from c4d import gui

answer = gui.QuestionDialog("Do you think I am a dialog?")
if answer:
    print ("You are right.\n I am a dialog") 
else:
    print ("You are wrong.\n I really am a dialog.")


-Niklas


Edited by NiklasR - 2012 Mar 19 at 12:49pm
Back to Top
kornyclown View Drop Down
Member
Member


Joined: 2012 Mar 19
Online Status: Offline
Posts: 2
Direct Link To This Post Posted: 2012 Mar 19 at 1:31pm
Ah, ok that makes sense, I didn't consider that True is always True. I was thingking a bit too "human".

Works fine, thanks a lot.
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.