Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 80 81 [82] 83 84 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100505 times)

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1215 on: December 04, 2013, 08:12:18 pm »

Have a look here: http://en.sfml-dev.org/forums/index.php?topic=12058.msg92608#msg92608

I don't know what Python 3.3 brings to the table, but perhaps it's worth reverting to 3.2?

Grand Nagus

  • Bay Watcher
  • A Ferengi without profit is no Ferengi at all.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1216 on: December 19, 2013, 11:45:43 pm »

Hi guys, I'm having issues. I've been learning programming on and off for years with the goal of making VERY simple games on very simple GUIs. Simple as in text readouts to bland Tkinter buttons. I'm really not looking to be some professional programmer, I just want to make simple retro style turn based games for myself.

However I keep having Issues, I feel as if I am yet again doing things the incredibly slow way and manually writing like 5 lines of code to get 1 button to work. I also have been having issues making classes readout into labels, I think the classes i've set up are faulty or im using them wrong, they never readout on the labels. But this is besides the point, I'd have to code 3 or 4 times what I currently have just to have the storage of chosen weapons pre game. It feels wrong to me.

one of my current projects is this 'Terrorist simulator'. It's mostly a joke program to help me learn, the concept being you are a group of terrorists taking a house, you can perform several actions and negotiate with the SWAT outside with them eventually deciding to assault the building and kill you all(unless you have escaped before then!)

The design is fine, I know what screens I need, what logic I need and where it goes. But I feel my coding is woefully inefficient and poorly designed. I have copious notes on such things.

Does anyone have any pointers on how I could improve my coding? I'm coding in python 2.7.
I've read plenty of stuff on making games but theyre mostly platformers using pygame or fps or whatnot, I just want to make pretty much rpg/strategy games with as simple a GUI as I can possibly do.

*The buttonmake and buttonkill etc are dead, I'm not using them. I don't think it works to make create a button through a function this way, I had issues with it.




Code: [Select]
"""Swat game
make items dictionary

fix two menus open at same time bug

"""

import random
from Tkinter import *


#guns
class guns():
glockdmg=1
galildmg=3
ak47dmg=4

class stats():
#skills
Bravery=1
Charisma=1
Respect=1
Negotiating=1
Pistols=1
Rifles=1
Submachineguns=1
Knives=1
Explosives=1
Hacking=1
Lockpicking=1

class attr():
#attributes
Mood= "Nostalgic"
Weapon="Bad breath"
hp=1

class terrorist(guns,stats,attr):
gun=""
moral=5

class player(terrorist):
php=1


#ASSIGNS CURRENT PLAYER TO THIS
current_player=""


jeff = player
jeff.gun="glock"
jeff.hp=2
print jeff.php


#die roll
def droll(d):
roll = random.randint(1,(d-1))
return roll

#initrandomisation
def initrand(terrorist):
#random stats
for t in terrorist:
t1s[t] = droll(10)





#randomise stats


#window
root = Tk()
root.title("gui")
root.geometry("360x320")
app = Frame(root)
app.grid()



#IMAGES
#title
imgPath = r"tpic.gif"
photo = PhotoImage(file = imgPath)
tpic = Label(app,image = photo)
tpic.image = photo # keep a reference!

#interface quicks
def buttonmake(name,desc,order):
name = Button(app, text = desc, command = order )
name.grid()

def buttonkill(name):
name.grid_forget()

def labelmake(name,color,row,column):
name = Label(app, bg=color,height=2,width=5)
name.grid(row=row, column=column)

#print skills BROKEN ONLY SHOWS 1
#def readout(terrorist,element):


#opening/closing stats box
def peekd():
statsl.grid(row=1,columnspan=4, pady = 50)
statc.grid(row=2, columnspan=4)
def peeku():
statsl.grid_forget()
statc.grid_forget()

#open/close negotiation window
def negpeekd():
moodl.grid(row=2,column=1, sticky=W, columnspan=2)
h_trade.grid(row=3,column=1,sticky=W,columnspan=2)
negc.grid(row=4,column=1,sticky=W)
chosentitle.grid(row=2,column=3, columnspan =2)
n1.grid(row=3,column=3,columnspan =2)
convo.grid(row=2, column=2,rowspan=4)
def negpeeku():
moodl.grid_forget()
h_trade.grid_forget()
negc.grid_forget()
n1.grid_forget()
chosenl.grid_forget()
chosentitle.grid_forget()
convo.grid_forget()



#popup
def newwindow():
root = Tk()
root.title("test")
root.geometry("200x400")
app = Frame(root)
app.grid()

selected = StringVar()
def negsel():
sel = "You have picked " + str(selected.get())
chosenl.config(text = sel)
chosenl.grid(row=4,column=3,columnspan =2)

def start():
events.config(text=tintro)
tpic.grid_forget()
sbutton.config(text="Quit")



#moral to be implimented
mood = "Calm"

group= ""
evil1=""
evil2=""
tintro = "You are a terrorist for the " + str(group) + "and you are going to make a statement to the westerners for their " + str(evil1) + "and " + str(evil2) + "\nYou are outside the house of the Kardashian's, a wealthy family to make an example of.\n\nWhat do you do now?"



#menu start button
sbutton = Button(app, text = "Start",activebackground = "red", bd = 4, cursor = "dot", command = start, bg = "red")
sbutton.grid(row=0, column = 0,sticky=W)

#menu negotiation
neg = Button(app, text = "Negotiate",activebackground = "red", bd = 4, cursor = "dot", command = negpeekd)
neg.grid(row=0, column = 1,sticky=W)

#conversation window
convo = Message(app,text="conversation here",relief=RAISED)

#terrorist pic
tpic.grid(row=9,columnspan=10)

#event messages
events = Message(app, text = "Press start...",width="250",pady=10,relief=RAISED)
events.grid(row=10, columnspan=10)

#menu team management
tm = Button(app, text = "Team management", activebackground = "red", bd = 4, cursor = "dot")
tm.grid(row=0, column = 2,sticky=W)

#show stats
statsl = Message(app,text = "",relief=RAISED,width=150)

#Negotiation options elements
moodl = Message(app, text = "Mood: "+str(mood), relief=RAISED,justify=LEFT)
h_trade = Button(app, text = "Trade", activebackground = "red", bd = 4, cursor = "dot",justify=LEFT)

#negotiation wholist
chosentitle = Message(app, text = "Who negotiates?")
n1 = Radiobutton(app, text="Jeff", value="Jeff", variable = selected, command = negsel)

#show selection
chosenl = Message(app)

#stats window
stats = Button(app, text = "Stats", activebackground = "red", bd = 4, command = peekd,cursor = "dot", padx = 48, bg = "blue")
stats.grid(row=0, column = 3)

#close windows
statc = Button(app, text = "close", activebackground = "red", bd = 4, command = peeku,cursor = "dot",bg = "red")
negc = Button(app, text = "close", activebackground = "red", bd = 4, command = negpeeku,cursor = "dot",bg = "red")




if player.php<=0:
events.config(text= "YOU DIED, NOOB!")


#init loop
root.mainloop()





« Last Edit: December 19, 2013, 11:56:40 pm by Grand Nagus »
Logged

HopFlash

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1217 on: December 21, 2013, 07:14:43 pm »

Went through that recently. Look at cx_Freeze. I couldn't make it work for Python 3.3, but apparently works, but is fiddly, with Python 3.2. Best of luck, and do report back!
Darn, cx_freeze is what I've been trying as it's the only thing I could find that even seems to attempt 3.3 compatibility.  I can't make heads or tails of it, I've tried excecuting commands in the python command prompt and the windows command prompt and get nothing but error messages.

On the cx_freeze page (http://cx-freeze.sourceforge.net/) there is a version for Python 3.3 and 3.4 (beta) out. You are sure you had installed it for this specific Python versions?
I tried it on Windows 7 64bit and it works fine...perhaps you have more than one Python version installed and not put cx_freeze into the right one?
Logged
GENERATION 11: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

Inactive Therian Saga Char: Stormhead
Dominions: 4.03 Berytos; 4.06 Pangaea; 4.08 Arcoscephale; 4.11 Shinuyama
Inactive Wurm Online Char: Stormhead

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1218 on: December 25, 2013, 10:31:16 pm »

SNIP

Congratulations on renouncing your american citizenship and/or any potential visa in the future!

On the cx_freeze page (http://cx-freeze.sourceforge.net/) there is a version for Python 3.3 and 3.4 (beta) out. You are sure you had installed it for this specific Python versions?
I tried it on Windows 7 64bit and it works fine...perhaps you have more than one Python version installed and not put cx_freeze into the right one?

That page looks quite a bit different than what I remember looking at. They might've updated it. I'll need to have a look! Thanks!

BoboJack

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1219 on: December 27, 2013, 10:01:07 am »

SNIP

Congratulations on renouncing your american citizenship and/or any potential visa in the future!

Are you promoting self-censorship?

Grand Nagus:

I have a hard time understanding your code. There's barely any abstraction visible.
You're misusing classes. You are using them as if they were dictionaries.
Things like
Spoiler (click to show/hide)
could be replaced by
Spoiler (click to show/hide)
called Dictionaries
Dictionaries are simpler than classes, you should avoid the complicated things and pursue whats simple and obvious.

But actually you should restructure your code.
Look at the player class for example.
Spoiler (click to show/hide)

It only has data. With classes you can also bundle functions with the player, to make clear that the player is doing something.
I will not try to explain how that exactly works. That would be hard. You can read that up somewhere.
how it could look like :
Spoiler (click to show/hide)
I just tried to show you how your code could look like if you would abstract the things in your mind,
like player and terrorist into code that would represent exactly these ideas.
Your code instead just has data and functions all around without any apparent structure or connection.

« Last Edit: December 27, 2013, 10:04:23 am by BoboJack »
Logged

mainiac

  • Bay Watcher
  • Na vazeal kwah-kai
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1220 on: December 30, 2013, 02:32:45 am »

Does anyone know why py2exe might be throwing me errors saying that it can't find py2exe when I run my setup script?  I changed things to python2.7 compatibility so that isn't it.


The trouble code is this:
https://drive.google.com/file/d/0B3vdHCmP0WVNYTBXdEQ2dlF5akU/edit?usp=sharing
Logged
Ancient Babylonian god of RAEG
--------------
[CAN_INTERNET]
[PREFSTRING:google]
"Don't tell me what you value. Show me your budget and I will tell you what you value"
« Last Edit: February 10, 1988, 03:27:23 pm by UR MOM »
mainiac is always a little sarcastic, at least.

magmaholic

  • Bay Watcher
  • "Hello again"- canadian stalker
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1221 on: December 30, 2013, 11:06:14 am »

Anyone know where i could get a source code for C++ syntax checker?
Logged
I am a Goober.

mainiac

  • Bay Watcher
  • Na vazeal kwah-kai
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1222 on: December 30, 2013, 11:46:28 am »

Well I never got py2exe working but cx_Freeze ended up working and it's okay with 3.3.
Logged
Ancient Babylonian god of RAEG
--------------
[CAN_INTERNET]
[PREFSTRING:google]
"Don't tell me what you value. Show me your budget and I will tell you what you value"
« Last Edit: February 10, 1988, 03:27:23 pm by UR MOM »
mainiac is always a little sarcastic, at least.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1223 on: January 01, 2014, 12:31:25 am »

I have a question about if vs. else-if blocks.

I'm making a scrolling shooter game in Unity, and this is most of the code for a script that will make the ship move back and forth in a wave pattern.

Here's what the code originally looked like:

Spoiler (click to show/hide)

... which didn't work. It would check waved once and then never again.

But when I changed line 11 to "else if (waved == false)", it worked. Why did else-if work when an if-statement didn't? If it's one of those things that can only be answered by "That's just the way it works" then I'm fine, but I'd like to know for future reference.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

dennislp3

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1224 on: January 01, 2014, 12:55:28 am »

I have a question about if vs. else-if blocks.

I'm making a scrolling shooter game in Unity, and this is most of the code for a script that will make the ship move back and forth in a wave pattern.

Here's what the code originally looked like:

Spoiler (click to show/hide)

... which didn't work. It would check waved once and then never again.

But when I changed line 11 to "else if (waved == false)", it worked. Why did else-if work when an if-statement didn't? If it's one of those things that can only be answered by "That's just the way it works" then I'm fine, but I'd like to know for future reference.

If works by saying "If(conditions = true) then run code, if(conditions = false) then break loop (because it is not explicitly told to look for more options)"

else if works by saying "If(conditions = true) then run the code, if(conditions = false) look for another option (if statement)"

At least thats what I think is going on...I am tired and it is late...so I may be looking at your code wrong...
« Last Edit: January 01, 2014, 12:57:36 am by dennislp3 »
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1225 on: January 01, 2014, 07:05:27 am »

'=' sets it to.

'==' compares.

I've made the mistake a whole lot, haha. Lots of segfaults that were ass to hunt down.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1226 on: January 01, 2014, 07:20:02 am »

I have a question about if vs. else-if blocks.

I'm making a scrolling shooter game in Unity, and this is most of the code for a script that will make the ship move back and forth in a wave pattern.

Here's what the code originally looked like:

Spoiler (click to show/hide)

... which didn't work. It would check waved once and then never again.

But when I changed line 11 to "else if (waved == false)", it worked. Why did else-if work when an if-statement didn't? If it's one of those things that can only be answered by "That's just the way it works" then I'm fine, but I'd like to know for future reference.
This is quite simple. If you don't include an else if, then if waved is true, then it will be set to false which will cause the if (waved == false) statement to execute, so that both statements would be executed if waved is true at the start of the Update function.
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1227 on: January 01, 2014, 10:14:07 am »

Here's what the code originally looked like:

Spoiler (click to show/hide)

... which didn't work. It would check waved once and then never again.

But when I changed line 11 to "else if (waved == false)", it worked. Why did else-if work when an if-statement didn't? If it's one of those things that can only be answered by "That's just the way it works" then I'm fine, but I'd like to know for future reference.
Run it through in your head.

1) waved is true
2) if (waved == true) activates, because waved is true
    waved is set to false
3) if (waved == false) activates because waved is false
    waved is set to true

if waved is false, then skip to 3.

The thing doesn't automagically know that you wanted it to remember what waved was from the start.

just use
Code: [Select]
if (waved) {BLUHBLUH}
else {ARGEBLARG}
if-else blocks do a single check. If waved is true, then it does BLUHBLUH, else it does ARGEBLARG, and then you can do whatever the hell you wanna do with waved.

Or if you like doing things in a very weird way, then do
Code: [Select]
tempwaved = waved
if (tempwaved == true) {waved = false}
if (tempwaved == false) {waved = true}
which has the same behaviour but takes more memory and is slower.
« Last Edit: January 01, 2014, 10:21:04 am by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1228 on: January 02, 2014, 09:58:35 am »

Or just goal_1.x += ((waved = !waved) ? 1.0f : -1.0f) * waveLength;
Although I don't know if that's valid in C#...
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1229 on: January 02, 2014, 11:05:00 am »

Or just goal_1.x += ((waved = !waved) ? 1.0f : -1.0f) * waveLength;
Although I don't know if that's valid in C#...

It is valid code, but it probably won't help him since he is having issues with else ifs, and that code is more difficult to read than simple if statements for most people.
Pages: 1 ... 80 81 [82] 83 84 ... 91