[Tutor] Passing numeral result of a defined function to a named value
Emile van Sebille
emile at fenx.com
Wed Jul 4 17:09:14 CEST 2012
On 6/28/2012 11:51 PM Joseph Hines said...
> Hello. Sorry to bother you, but I'm self-teaching myself python, and
> having difficulty with a script I'm writing to auto-calc various derived
> stats for a PnP game I am hosting soon.
>
> I need to pass a numeral result of a defined function to a "named" value
> (not sure if that's what it's called)
>
> The offending segment of code is this:
>
... and what's the offending error? (provide traceback details please)
Do you mean to be defining a function within a try-except structure? As
it stands you'll get a syntax error.
You've likely got an indetation issue on the line before except.
providing int_mod as some integer and reworking it to:
XP_Per_Level_Base = 20-int_mod
XP_Per_Level_Limit = 5
try:
def XP_Per_Level_Calc(XP_Per_Level_Base, XP_Per_Level_Limit):
if XP_Per_Level_Base < XP_Per_Level_Limit:
return XP_Per_Level_Limit
else:
return XP_Per_Level_Base
except ValueError:
print "Script B0RK3D, Link Shall Come to Town."
print "send him a message at
Link6746 at gmail.com<mailto:Link6746 at gmail.com>"
XP_Per_Level = XP_Per_Level_Calc(XP_Per_Level_Base, XP_Per_Level_Limit)
gets it going, dut all in all it looks to me like this is simply a max
function and could be written more simply as:
max(XP_Per_Level_Base,XP_Per_Level_Limit)
Emile
>
> XP_Per_Level_Base = 20-int_mod
> XP_Per_Level_Limit = 5
> try:
> def XP_Per_Level_Calc(XP_Per_Level_Base, XP_Per_Level_Limit):
> if XP_Per_Level_Base < XP_Per_Level_Limit:
> return XP_Per_Level_Limit
> else:
> return XP_Per_Level_Base
> XP_Per_Level = XP_Per_Level_Calc(XP_Per_Level_Base, XP_Per_Level_Limit)
> except ValueError:
> print "Script B0RK3D, Link Shall Come to Town."
> print "send him a message at Link6746 at gmail.com
> <mailto:Link6746 at gmail.com>"
>
> #Calcs XP per Level#
>
>
> If you need the whole script, I'd be glad to send it to you, just
> promise me not to divulge too many details of it
> (It's regarding a custom PnP system that I'm planning on releasing under
> the Open Gaming License, and I'd prefer not to risk it becoming a
> proprietary system for someone I don't know)
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list