473,562 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the if-statement that fixes it all, but my computer just skips it.

7 New Member
by now, you have no doupt replied to many of mine and my buddy (børntard)'s questions about our faulty programming concerning the over-complicated mega-script to design your dungeons and dragons roleplaying character.

well, i think i have cracked it. but theres one slight problem i cant seem to get my head wrapped around. i have an IF-statement in my script. well, i have a rediculous ammount actually. but my script skips one of them, and its really irritating because in my eyes, it will fix my problems.

Expand|Select|Wrap|Line Numbers
  1. name=raw_input('What do you want to call your character? ')
  2.  
  3. Strength1 = '' #just defining these so my script doesnt get mad at me and give me an error later
  4. Strength2 = ''
  5.  
  6. for x in range(1,100): #runs the thing a few times, since the potensial for error is relatively big, as you can see in the way too long *if value = value or value2 = value2 thing a bit further down
  7.  
  8.  import random
  9.  
  10.  S1 = random.randint(1, 6)
  11.  S2 = random.randint(1, 6)
  12.  S3 = random.randint(1, 6)
  13.  S4 = random.randint(1, 6)
  14.  
  15.  if S1 < S2 and S1 < S3 and S1 < S4: #rolls a 6 sided dice and removes the one with lowest score, then adds the 3 that rolled highest into a new value called S5. 
  16.      S5 = S2 + S3 + S4
  17.  elif S2 < S1 and S2 < S3 and S2 < S4: 
  18.      S5 = S1 + S3 + S4
  19.  elif S3 < S1 and S3 < S2 and S3 < S4: 
  20.      S5 = S1 + S2 + S4
  21.  elif S4 < S1 and S4 < S3 and S4 < S2: 
  22.      S5 = S1 + S3 + S2
  23.    if S1==S2 or S1==S3 or S1==S4 or S2==S1 or S2==S3 or S2==S4 or S3==S1 or S3==S2 or S3==S4 or S4==S1 or S4==S2 or S4==S3
  24.      print ''
  25.  
  26. print '....... Ability Values .......'
  27. print 'Value 1 = %s ' % S5
  28. print 'Value 2 = %s ' % D5
  29. print 'Value 3 = %s ' % C5
  30. print 'Value 4 = %s ' % I5
  31. print 'Value 5 = %s ' % W5
  32. print 'Value 6 = %s ' % CH5
  33. print '..............................'
  34. print 'You must now choose which of your ability values will be your traits.'
  35. print '..............................'
  36. Strength1=raw_input("Strength affects the ability of characters to lift and carry weights and make effective melee attacks. Please decide which of your ability scores will be your strength score, and type in the corresponding number. ") 
  37.  
  38. if Strength1==1:
  39.     print '........................'
  40.     print 'your strength is now %s.' % S5
  41.     Strength2=S5
  42. elif Strength1==2:
  43.     print '........................'
  44.     print 'your strength is now %s.' % D5
  45.     Strength2=D5
  46. elif Strength1==3:
  47.     print '........................'
  48.     print 'your strength is now %s.' % C5
  49.     Strength2=C5
  50. elif Strength1==4:
  51.     print '........................'
  52.     print 'your strength is now %s.' % I5
  53.     Strength2=I5
  54. elif Strength1==5:
  55.     print '........................'
  56.     print 'your strength is now %s.' % W5
  57.     Strength2=W5
  58. elif Strength1==6:
  59.     print '........................'
  60.     print 'your strength is now %s.' % CH5
  61.     Strength2=CH5
  62.  
  63.         #this is where the problem lies. i dont know why, but my computer doesnt seem to wanna do this if statement. it simply skips it, and its really irritating, because i have a feeling it will all work out if my computer stops thinking "oh, whats this? and if statement? well, that cant be important, lets skip it."
  64.  
  65. print '.............................'
  66. print 'Your strength is now %s' % Strength2
this piece of code is merely a small piece of my big script, but its all basically the same. allow me to explain how i imagine it will happen.

by typing in the correct number in the console, you assign that number to Strength1. then, the if-statement checks Strength1's value, and makes Strength2 the correct size of the character's strength. then it prints the strength. however when i run this script, it simply tells me that my strength is *empty space* :(
Jun 1 '07 #1
3 1211
Smygis
126 New Member
Your trying to compare a string with an integer. Thats the problem, you can solve it by putting a
Expand|Select|Wrap|Line Numbers
  1. int()
around the raw_input()

Expand|Select|Wrap|Line Numbers
  1. Strength1 = int(raw_input("Strength affects the ability of characters to lift and carry weights and make effective melee attacks. Please decide which of your ability scores will be your strength score, and type in the corresponding number. "))

You might want to read this thread aswell
http://www.thescripts.com/forum/thread655851.html
Uhm... Is that your friend? BurnTard?
Jun 1 '07 #2
ghostdog74
511 Recognized Expert Contributor

Expand|Select|Wrap|Line Numbers
  1. ....
  2. for x in range(1,100): #runs the thing a few times, since the potensial for error is relatively big, as you can see in the way too long *if value = value or value2 = value2 thing a bit further down
  3.  
  4.  import random
  5.  
try to put your import on top of your script to import it once.
Jun 2 '07 #3
BurnTard
52 New Member
Your trying to compare a string with an integer. Thats the problem, you can solve it by putting a
Expand|Select|Wrap|Line Numbers
  1. int()
around the raw_input()

Expand|Select|Wrap|Line Numbers
  1. Strength1 = int(raw_input("Strength affects the ability of characters to lift and carry weights and make effective melee attacks. Please decide which of your ability scores will be your strength score, and type in the corresponding number. "))

You might want to read this thread aswell
http://www.thescripts.com/forum/thread655851.html
Uhm... Is that your friend? BurnTard?
Yup, he's my buddy. I told him the easy way, but he says he has to do this the hard way, to get better at scripting, which I understand.
Jun 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2511
by: Ryan Lowe | last post by:
i thought id ask here before wirting a PEP, if people thought it would be a good enhancement to allow if clauses in regular for-statements like so: >>> for x in y if x < 10 : is semantically equivalent to >>> for x in : but is shorter and easier to read. basically, the if works as a filter for
3
3877
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't understand why this 'Expected 'End'' error is called! Here is my code: <%
9
13753
by: Marek Lewczuk | last post by:
Hello, I'm moving out from MySQL to PostgreSQL and there are some function which are not supported in PG so I'm trying to write my own functions. Currently I have big problem with function IF(), below the description of this function from MySQL manual. Anybody can help me with this ?? I think that PLPGSQL language can be used or maybe...
15
24779
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that contains the subform is named Clients. I have this code in the Add Client btn: If Forms!Clients.subformVisits!VisitDirty = True Then MsgBox "Visit...
35
2688
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And I'm pretty sure the rest of the program is working just fine. The only thing I could think might be wrong is that the if statement can only hold so...
73
2689
by: Martin Johansen | last post by:
if(a); In this code, towhat type does the if statement cast the variable "a" to on comparizon?
2
4766
by: William | last post by:
The script below runs correctly in ASP but not ASPX. Im not sure why? Please help. Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30081: 'If' must end with a...
8
3160
by: fredda054 | last post by:
Hi everybody ! I have a little repeater/hyperlink issue I'm not sure how to solve. I use a repeater to list subjects available at a specific school. The datasource of this repeater is a dataset filled with info from a SQL Server database. All the subjects are displayed as hyperlinks, and when a user clicks a subject, it opens up a new...
0
2619
by: Benny Ng | last post by:
Hi,All, When i deploy Enterprise library with my application ,i used XCOPY to deploy it into my test server. But when application runs, shown some error related registry. (But actually I haven't any method or component to wrote registry) After I used "InstallUtil" to registry Enterprise Library (those DLLs) to the deployment server, the...
3
3926
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the right direction about what I am not doing correctly? 1.. Write an If Then Else statement that displays the string "Pontiac" in the CarMakeLabel...
0
7652
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7625
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7934
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6219
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5476
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5193
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1187
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.