Author Topic: The "I Need Help With Code" Thread  (Read 1417 times)

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
The "I Need Help With Code" Thread
« on: January 28, 2013, 02:24:00 PM »
Because I don't want to make a new thread every time I mess up in a new programming language.

So I'm learning VBscript and I'm getting a compile error every time because apparently there's a loop without a do.

Code: [Select]
Dim no

no = 10

Set obj = CreateObject("Scripting.FileSystemObject")

Do while no = 10
    If obj.FolderExists("..\world") Then
    obj.CopyFile "..\world", "..\Backups"
    WScript.sleep 86400000 '1 day in milliseconds, according to google.
Loop while no = 10
But, as you can see, there is a Do (Line 7). So, how do I fix this?
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots

Offline Pwnator

  • *
  • Posts: 6676
  • Rep: 15
  • Awards BOTM Winner
    • View Profile
    • http://pwnator.tumblr.com
    • Awards
  • See profile for gamer tags: Yes
Re: The "I Need Help With Code" Thread
« Reply #1 on: January 28, 2013, 05:17:20 PM »
Don't really know anything much about VB (other than he is actually Scrap), but have you tried placing parentheses on the conditions?
Clash Cubes 1 - Grey Matter (Runner-Up)
King of Karnage - Sideshow Freak (Runner-Up, Best Engineered)
Rust In Pieces - Paper Cut 3 (Grand Champion, Most Dangerous Bot)
Wheely Tag Tournament - Ion Thruster (Grand Champion, along with Ounces' DiSemboweLment)
UK vs USA - Dark Striker (Grand Champion)
Rust In Pieces 2 - Claymore (Runner-Up, Favourite Bot)
BBEANS 6 - Infection 4 (Runner-Up)
RA2 Team Championships - Serious Business, Skeksis (Runner-Up, along with Scrappy, S_M, and Badnik)
RA2 Team Championships 2 - The Other Stig (Runner-Up, along with Scrappy, S_M, Badnik, 090901, and R1885)
Replica Wars 3 - Abaddon (Runner-Up, Luckiest Bot)
BroBots - wheebot & yaybot (Runner-Up)
Robo Zone 2 - Dipper (4th place, Survival Champion, & Best Axle Bot)
ARBBC - The Covenant (3rd place, BW Rumble Winner, Most Feared BW)

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
Re: The "I Need Help With Code" Thread
« Reply #2 on: February 01, 2013, 02:33:37 PM »
The If statement in the loop didn't have and 'End If'. Stupid mistake, strange error message.

I have a new problem now, the script won't detect the world/autosave folders. The code and folder is below.



Code: [Select]
Set obj = CreateObject("Scripting.FileSystemObject")

Dim worldfolder
Dim backupfolder

worldfolder = "..\world"
backupfolder = "..\autosave"

Do
    If (obj.FolderExists("..\world")) Then
    msgbox "World file found!"
    obj.CopyFolder "..\world", "..\autosave"
    obj.CopyFile "..\world\*", "..\autosave"
    msgbox "Autosave complete!"
    Else
    msgbox "Error"
    Wscript.quit
    End If
        WScript.sleep 21600000 '6 hours in milliseconds, according to google.
Loop
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
Re: The "I Need Help With Code" Thread
« Reply #3 on: July 14, 2013, 06:44:26 AM »
Alright, so now in Python 3.3 (don't ask why) I keep getting a syntax error with the following code:

Code: [Select]
import math
print("A^2 x 2B x C")
numa = input('What is A? ')
numb = input('What is B? ')
numc = input('What is C? ')
firstanswer = (numb + math.sqrt((math.pow(numb,2)+4*numa*numc))/(2*numa)
secondanswer = (numb - math.sqrt((math.pow(numb,2)+4*numa*numc))/(2*numa)
print("The answer is")
print(firstanswer)
print("or")
print(secondanswer)

And when I try to run it, I get the following error:

Code: [Select]
    secondanswer = (numb - math.sqrt((math.pow(numb,2)+4*numa*numc))/(2*a)
               ^
SyntaxError: invalid syntax

What am I doing wrong? Why is this only happening with the second variable? Why doesn't it run the program until it encounters the error, rather than just flagging it up? =S
« Last Edit: July 14, 2013, 09:38:25 AM by TheRoyalBadger »
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots

Offline Pwnator

  • *
  • Posts: 6676
  • Rep: 15
  • Awards BOTM Winner
    • View Profile
    • http://pwnator.tumblr.com
    • Awards
  • See profile for gamer tags: Yes
Re: The "I Need Help With Code" Thread
« Reply #4 on: July 14, 2013, 06:51:53 AM »
Code: [Select]
    secondanswer = .../(2*a)
Looks like that's the problem. I'm gonna guess 'a' should be 'numa'.

hooray for quadratic equations


[Edit] Ah, crap. Forgot bold or italic doesn't work within codes. :<
Clash Cubes 1 - Grey Matter (Runner-Up)
King of Karnage - Sideshow Freak (Runner-Up, Best Engineered)
Rust In Pieces - Paper Cut 3 (Grand Champion, Most Dangerous Bot)
Wheely Tag Tournament - Ion Thruster (Grand Champion, along with Ounces' DiSemboweLment)
UK vs USA - Dark Striker (Grand Champion)
Rust In Pieces 2 - Claymore (Runner-Up, Favourite Bot)
BBEANS 6 - Infection 4 (Runner-Up)
RA2 Team Championships - Serious Business, Skeksis (Runner-Up, along with Scrappy, S_M, and Badnik)
RA2 Team Championships 2 - The Other Stig (Runner-Up, along with Scrappy, S_M, Badnik, 090901, and R1885)
Replica Wars 3 - Abaddon (Runner-Up, Luckiest Bot)
BroBots - wheebot & yaybot (Runner-Up)
Robo Zone 2 - Dipper (4th place, Survival Champion, & Best Axle Bot)
ARBBC - The Covenant (3rd place, BW Rumble Winner, Most Feared BW)

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
Re: The "I Need Help With Code" Thread
« Reply #5 on: July 14, 2013, 06:58:04 AM »
Thanks, I can't believe I made such a stupid mistake. I wish variables worked properly in Python. This weakly typed rubbish is annoying. Oh, and if I'm starting with a programming language, I always make a quadratic calculator as soon as I learn the math. May as well make something useful out of it ASAP.

Edit:


Nope, same error. It's very odd how the 1st variable doesn't give an error but the near identical 2nd one does.
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots

Offline noogai03

  • Antweight
  • Posts: 16
  • Rep: 0
  • memes
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: The "I Need Help With Code" Thread
« Reply #6 on: July 14, 2013, 12:02:45 PM »
Code: [Select]
import math
import __future__  #SORRY I GOT THIS WRONG FIRST TIME

print "A*x^2+B*x+C"
a = input()
b = input()
c = input()


#make sure no invalid stuff is happening, to prevent division
#by 0, sqrt of minus nos
if b ** 2 - 4*a*c < 0 or 2*a ==0:
    print "error"
    exit()


ans1 = (  -b + math.sqrt(  (b ** 2)-(4*a*c)  )) / (2*a)
ans2 = (  -b - math.sqrt(  (b ** 2)-(4*a*c)  )) / (2*a)

print ans1
print ans2

My version, this should work fine
Noogai03

Offline noogai03

  • Antweight
  • Posts: 16
  • Rep: 0
  • memes
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: The "I Need Help With Code" Thread
« Reply #7 on: July 14, 2013, 12:08:23 PM »
Code: [Select]
import math
print("A^2 x 2B x C")
numa = input('What is A? ')
numb = input('What is B? ')
numc = input('What is C? ')
firstanswer = (-numb + math.sqrt(numb**2 - 4*numa*numc))/(2*numa)
secondanswer = (-numb - math.sqrt(numb**2 - 4*numa*numc))/(2*numa)
print("The answer is")
print(firstanswer)
print("or")
print(secondanswer)
Fixed your version - the formula was wrong and I think math.pow() broke it
Noogai03

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
Re: The "I Need Help With Code" Thread
« Reply #8 on: July 14, 2013, 12:15:14 PM »
Fixed. Brackets, man. FML. Thanks to all who responded.
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots

Offline Badger

  • Permanent Artifact
  • Giga Heavyweight
  • Posts: 6298
  • Rep: 2
  • I wish to be with my people
  • Awards BOTM Winner Donated money for site hosting 2019
    • View Profile
    • Awards
Re: The "I Need Help With Code" Thread
« Reply #9 on: August 27, 2013, 06:52:47 PM »

Alright, managed to pinpoint the problem

Code: [Select]
numbertocheck = numberslist[x]I want to take a number from numberslist with index number 'x', and compare it to this variable:
Code: [Select]
    pivot = numberslist[pivotindex]
However, the variable 'pivot' is an integer (as expected). However, python is treating 'numbertocheck' as a list, making it incomparable to pivot! Why is this, and how can I fix it?
« Last Edit: August 27, 2013, 07:52:58 PM by TheRoyalBadger »
also lol at most toxic guy around calling others out on this sh**
Google Drive with my newer bots