• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:09
CEST 15:09
KST 22:09
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 13-19): Clem Goes for Four0BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80Weekly Cups (Sept 29-Oct 5): MaxPax triples up3
StarCraft 2
General
The New Patch Killed Mech! Team Liquid Map Contest #21 - Presented by Monster Energy herO joins T1 Weekly Cups (Oct 13-19): Clem Goes for Four TL.net Map Contest #21: Voting
Tourneys
INu's Battles #13 - ByuN vs Zoun Tenacious Turtle Tussle SC2's Safe House 2 - October 18 & 19 Sparkling Tuna Cup - Weekly Open Tournament $1,200 WardiTV October (Oct 21st-31st)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
BSL Season 21 BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ BW caster Sayle BSL Team A vs Koreans - Sat-Sun 16:00 CET
Tourneys
[ASL20] Semifinal B Azhi's Colosseum - Anonymous Tournament [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN
Strategy
Current Meta BW - ajfirecracker Strategy & Training Relatively freeroll strategies Siegecraft - a new perspective
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club!
Media & Entertainment
Series you have seen recently... Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1278 users

The Big Programming Thread - Page 54

Forum Index > General Forum
Post a Reply
Prev 1 52 53 54 55 56 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17386 Posts
Last Edited: 2011-05-12 14:32:07
May 12 2011 13:15 GMT
#1061
@Bobbias:
Why make a game engine on your own? Get a MUD (the driver and code) and you get your engine, all with standard libraries and stuff. Then, you can do whatever you want with it. Just host it as a server and make user connect via loopback. It takes almost no resources (I once hosted a MUD on my free 15MB shell account without super user privilages) or trouble. It's perfect and it also gives you the option for multiplayer if you wish so.
Then you can focus solely on creating game content, for which you'll already have the tools at your disposal.
MUD doesn't need to be MUD you know. You can make it into a roguelike game but mudcode gives you more possibilities and makes it much more dynamic.
Time is precious. Waste it wisely.
Zocat
Profile Joined April 2010
Germany2229 Posts
May 12 2011 14:16 GMT
#1062
On May 11 2011 03:19 Manit0u wrote:
P. S. (not related to your question)

I've finally fixed my dice generator code, no seg faults, no floating point exceptions and looks good during debugging.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration();
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
void GenerateRandomSeed(void);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);
void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result);

int main(void)
{
struct DiceConfiguration *config;
struct DiceThrowsResult *result;

GenerateRandomSeed();

config = GetConfiguration();

while(config != NULL)
{
result = ThrowDices(config);

PrintDiceThrowsResult(result);

ReleaseMemory(config, result);

config = GetConfiguration();
}

return 0;
}

struct DiceConfiguration* GetConfiguration()
{
int diceNumber = 0;
int diceType = 0;

printf("Enter the number of dice to throw (0 to quit): ");
scanf("%d", &diceNumber);

if(diceNumber == 0)
{
return NULL;
}
else
{
printf("Enter dice type (sides) : ");
scanf("%d", &diceType);

if(diceType < 2)
{
printf("Dice can't have less than 2 sides!\n");
return NULL;
}
else
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

config->DiceNumber = diceNumber;
config->DiceType = diceType;

return config;
}
}
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

void GenerateRandomSeed(void )
{
srand((unsigned int) time(0));
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}

void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result)
{
if (config != NULL)
{
free(config);
config = NULL;
}

if (result != NULL)
{
free(result);
result = NULL;
}
}



Enjoy!


So - how do I throw 2 d6 and 1 d10 at the same time?
Manit0u
Profile Blog Joined August 2004
Poland17386 Posts
May 12 2011 14:28 GMT
#1063
On May 12 2011 23:16 Zocat wrote:
Show nested quote +
On May 11 2011 03:19 Manit0u wrote:
P. S. (not related to your question)

I've finally fixed my dice generator code, no seg faults, no floating point exceptions and looks good during debugging.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration();
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
void GenerateRandomSeed(void);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);
void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result);

int main(void)
{
struct DiceConfiguration *config;
struct DiceThrowsResult *result;

GenerateRandomSeed();

config = GetConfiguration();

while(config != NULL)
{
result = ThrowDices(config);

PrintDiceThrowsResult(result);

ReleaseMemory(config, result);

config = GetConfiguration();
}

return 0;
}

struct DiceConfiguration* GetConfiguration()
{
int diceNumber = 0;
int diceType = 0;

printf("Enter the number of dice to throw (0 to quit): ");
scanf("%d", &diceNumber);

if(diceNumber == 0)
{
return NULL;
}
else
{
printf("Enter dice type (sides) : ");
scanf("%d", &diceType);

if(diceType < 2)
{
printf("Dice can't have less than 2 sides!\n");
return NULL;
}
else
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

config->DiceNumber = diceNumber;
config->DiceType = diceType;

return config;
}
}
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

void GenerateRandomSeed(void )
{
srand((unsigned int) time(0));
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}

void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result)
{
if (config != NULL)
{
free(config);
config = NULL;
}

if (result != NULL)
{
free(result);
result = NULL;
}
}



Enjoy!


So - how do I throw 2 d6 and 1 d10 at the same time?


Launch the app, enter 2, 6, 1, 10.
I assume you can do basic math like addition on your own?
Time is precious. Waste it wisely.
Zocat
Profile Joined April 2010
Germany2229 Posts
May 12 2011 15:10 GMT
#1064
On May 12 2011 23:28 Manit0u wrote:
Show nested quote +
On May 12 2011 23:16 Zocat wrote:
On May 11 2011 03:19 Manit0u wrote:
P. S. (not related to your question)

I've finally fixed my dice generator code, no seg faults, no floating point exceptions and looks good during debugging.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration();
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
void GenerateRandomSeed(void);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);
void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result);

int main(void)
{
struct DiceConfiguration *config;
struct DiceThrowsResult *result;

GenerateRandomSeed();

config = GetConfiguration();

while(config != NULL)
{
result = ThrowDices(config);

PrintDiceThrowsResult(result);

ReleaseMemory(config, result);

config = GetConfiguration();
}

return 0;
}

struct DiceConfiguration* GetConfiguration()
{
int diceNumber = 0;
int diceType = 0;

printf("Enter the number of dice to throw (0 to quit): ");
scanf("%d", &diceNumber);

if(diceNumber == 0)
{
return NULL;
}
else
{
printf("Enter dice type (sides) : ");
scanf("%d", &diceType);

if(diceType < 2)
{
printf("Dice can't have less than 2 sides!\n");
return NULL;
}
else
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

config->DiceNumber = diceNumber;
config->DiceType = diceType;

return config;
}
}
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

void GenerateRandomSeed(void )
{
srand((unsigned int) time(0));
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}

void ReleaseMemory(struct DiceConfiguration *config, struct DiceThrowsResult *result)
{
if (config != NULL)
{
free(config);
config = NULL;
}

if (result != NULL)
{
free(result);
result = NULL;
}
}



Enjoy!


So - how do I throw 2 d6 and 1 d10 at the same time?


Launch the app, enter 2, 6, 1, 10.
I assume you can do basic math like addition on your own?


Nooooo ! Adding stuff is stupid! ^^
Just wanted to tease you a bit !
Bobbias
Profile Blog Joined March 2008
Canada1373 Posts
May 12 2011 17:03 GMT
#1065
Well its not like I have no experience at all. I was certainly planning on making a game as my final product, but I wanted to do more than just throw together a collection of hacks that somehow wind up creating a game. The purpose wasn't just to ind up with a game, but to really have learned some of the things I never got into learning when I was taking programming courses in high school (yeah, they weren't that serious, but by the end of it, I did have a fully functional 2D space invaders type game written in Java.)

All things considered I see this more as a way to learn more advanced coding practices, rather than an attempt just to make a game. It seems now that everyone makes games, but not everyone learns these advanced techniques.

So to sum things up a bit: The goal of this project is to learn some advanced game-making and programming concepts and to use them in an attempt to create a game.

I want to hard-code as little as possible into the game. Plus, anything I do hard code should be easily replaced with some other code or information (such as monster info loaded from an XML sheet).

I decided that I wanted the world to be open and non-linear because that means I don't actually need a storyline or quest system (although I'd like to add one).

C# provides quite a few tools to make various jobs easier (no need to write my own linked lists, no need to do detailed memory management, built in XML reading functionality) and I've downloaded the SDL.NET library to assist in the things that C# doesn't natively provide, so I'm not going to be totally re-inventing the wheel.
Manit0u
Profile Blog Joined August 2004
Poland17386 Posts
Last Edited: 2011-05-12 18:48:51
May 12 2011 18:30 GMT
#1066
On May 13 2011 02:03 Bobbias wrote:
Well its not like I have no experience at all. I was certainly planning on making a game as my final product, but I wanted to do more than just throw together a collection of hacks that somehow wind up creating a game. The purpose wasn't just to ind up with a game, but to really have learned some of the things I never got into learning when I was taking programming courses in high school (yeah, they weren't that serious, but by the end of it, I did have a fully functional 2D space invaders type game written in Java.)

All things considered I see this more as a way to learn more advanced coding practices, rather than an attempt just to make a game. It seems now that everyone makes games, but not everyone learns these advanced techniques.

So to sum things up a bit: The goal of this project is to learn some advanced game-making and programming concepts and to use them in an attempt to create a game.

I want to hard-code as little as possible into the game. Plus, anything I do hard code should be easily replaced with some other code or information (such as monster info loaded from an XML sheet).

I decided that I wanted the world to be open and non-linear because that means I don't actually need a storyline or quest system (although I'd like to add one).

C# provides quite a few tools to make various jobs easier (no need to write my own linked lists, no need to do detailed memory management, built in XML reading functionality) and I've downloaded the SDL.NET library to assist in the things that C# doesn't natively provide, so I'm not going to be totally re-inventing the wheel.


I'm trying to tell you here that making your entire text-based RPG from scratch is a bad idea. Take a look at the links I posted (about LPC language mostly), set up some MUD of your own, just for your own use and see how it works. You don't need to base your game off of it but you'll get a first hand experience of how things are done which could give you ideas for your work.
The biggest problem I see in writing your own engine/doing everything from scratch is that you would also have to write the entire documentation and manuals for everything (even if not to get lost yourself).
I mean, why re-invent the wheel? There are tools available (for free no less) and stuff people have been working on for 20 years now and you want to create roughly the same thing from scratch? Why? Could you explain?

And if you want to learn more advanced coding, why not create your own MUD driver? That's some really advanced stuff right there...

Helpful reading:
http://discworld.atuin.net/lpc/about/articles/starting_a_mud.html

And you can always take a look here:
http://sourceforge.net/projects/dgd-osr/
Time is precious. Waste it wisely.
Akka
Profile Joined August 2010
France291 Posts
Last Edited: 2011-05-12 20:57:02
May 12 2011 20:50 GMT
#1067
If you want to learn how to code better, then you just have to begin your project from scratch. You will face many problems that will make you have to learn better / more advanced stuff.
If you want to make everything from scratch eventually you'll have to learn how to separate different parts of your game, how some things can be done by loading scripts (e.g. Lua), which patterns are the most useful, etc. and at some point you will end up with a real game engine and something around it that should be pretty cool.
But you won't learn anything worth much just trying to use already existing tools in order to make your life easier (imho).

Coding a basic MUD from scratch in Cpp should take at most a few weeks (with a network interface and all that goes with it). Making it a bit sexier could take about a whole month. Turning it into something that looks really pro would take you much, much more time.
Bobbias
Profile Blog Joined March 2008
Canada1373 Posts
Last Edited: 2011-05-13 00:43:25
May 13 2011 00:41 GMT
#1068
1) I prefer C# to LPC.
2) I've considered making muds quite a few times, but I don't like the style where rooms are just text and objects, and you interact by typing commands, that's not my thing at all.
3) I want a learning experience that forces me to need to learn some of this stuff.
4) When I said text based, I meant that like Dwarf Fortress, everything would be rendered through text, not the traditional "You are standing in a room, what do you want to do?" text based.
5) Writing my own game engine, even if I never actually make a game, will teach me a lot more about programming than taking an existing system, like a mud and adding content.
Manit0u
Profile Blog Joined August 2004
Poland17386 Posts
May 13 2011 17:40 GMT
#1069
On May 13 2011 09:41 Bobbias wrote:
1) I prefer C# to LPC.
2) I've considered making muds quite a few times, but I don't like the style where rooms are just text and objects, and you interact by typing commands, that's not my thing at all.
3) I want a learning experience that forces me to need to learn some of this stuff.
4) When I said text based, I meant that like Dwarf Fortress, everything would be rendered through text, not the traditional "You are standing in a room, what do you want to do?" text based.
5) Writing my own game engine, even if I never actually make a game, will teach me a lot more about programming than taking an existing system, like a mud and adding content.


I see now. Then you should take a look at ADoM.

[image loading]
Time is precious. Waste it wisely.
xerwin
Profile Blog Joined August 2010
Czech Republic42 Posts
May 17 2011 15:01 GMT
#1070
Hey TL, got a little problem that I can't seem to get fixed. It's a simple one for those familiar with PHP and SQL but I simply don't like PHP ( I prefer c# or c++, even though they are similar).

I have a project for class, create a mini portal system, adding articles, editing, etc etc, but I'm stuck on the simplest thing possible. I can't seem to get data from DB to show.
Here is the part of code I have problems with:
+ Show Spoiler +
<?php
include_once 'connect.php'; //contains all the code necessary for SQL connection
$query = "SELECT * FROM `rs` ORDER BY `ID` DESC";
$result = mysql_query($query) or die(mysql_error());
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<?php while($row = mysql_fetch_array($result))
{?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">&nbsp;</td>
</tr>
</table>
<center><div style="text-align:justify;align:center;width:638px">
<center>
<table border="1" width="95%" bgcolor="#FF0000" bordercolor="#000000" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><b><font color="#FFFFFF" face="Arial" size="2">
<p align="left"><?php echo $row['ID'] ?>
<p align="center"><?php echo $row['name'] ?>
<p align="right"><?php echo $row['date'] ?>
</font></b></td>
</tr>
</table>
</center>
</div>
<center>
<center><div style="text-align:justify;align:center;width:638px">
<p align="justify" style="margin-left: 10; margin-right: 10"><font face="Arial" size="2"><?php echo $row['text']; ?>&nbsp;</font><br>
</center></div>
<?php };?>

When I try something like echo $row['name']."test"; and then reload the website, only "test" is written (without the ""). When I created new script and copied the PHP and SQL code without the HTML formatting, it worked.
Sorry if the code is messy or not valid, the HTML isn't mine, first I need to get it working, then I I'll clean up and fix errors.
Cloud
Profile Blog Joined November 2004
Sexico5880 Posts
Last Edited: 2011-05-17 16:37:15
May 17 2011 15:40 GMT
#1071
Xerwin, the <p>'s need closing (it's good style at least), also the last </center></div> should be </div></center>. And you should use CSS.
Your code seems ok otherwise.
BlueLaguna on West, msg for game.
xerwin
Profile Blog Joined August 2010
Czech Republic42 Posts
May 17 2011 17:53 GMT
#1072
On May 18 2011 00:40 Cloud wrote:
Xerwin, the <p>'s need closing (it's good style at least), also the last </center></div> should be </div></center>. And you should use CSS.
Your code seems ok otherwise.

Thanks, I'm an idiot, PSpad saved it as *.html instead of *.php
kerr0r
Profile Joined September 2008
Norway319 Posts
May 18 2011 18:15 GMT
#1073
Okay, I have a problem. It involves python, threading and exceptions. The script grabs thumbnail urls from a video site and translates them into video urls to bypass the paywall. It then downloads the videos one at a time. I wanted to extend the script to include threading, so I could download more than one video at a time. Here's the problem though: It includes a cleanup function that deletes the incomplete file when closing. This works fine in the single-file, non-threaded version, but with threading it won't work. It seems to me that it tries to delete the files before closing the download threads, thus not being able to (since those files are already being used). Is there any way to make sure the threads are closed before the cleanup function executes?

Here's the code:
+ Show Spoiler +
import atexit
import threading
from time import sleep
import re
import urllib
import os.path
from os import remove

currentfiles = []

class DlThread(threading.Thread):
def __init__(self, url, filename):
self.url = url
self.filename = filename
threading.Thread.__init__(self)

def run(self):
currentfiles.append(self.filename)
print "Downloading " + self.filename + "..."
urllib.urlretrieve(self.url, self.filename)
print self.filename + " downloaded! "
f = open('downloaded.txt', 'a')
print >>f, self.url
currentfiles.remove(self.filename)
f.close()

def uniquify(seq, idfun=None):
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result

def cleanup():
for file in currentfiles:
remove(file)

atexit.register(cleanup)

for pn in range(192):
pn += 1
url = "http://www.website.com/most-viewed/page%s.html" % (pn)
f = urllib.urlopen(url)
page = f.read()
f.close()

titlesraw = re.findall(r'alt="[^"]*"', page)
titles = []
for title in titlesraw:
title = title[5:-1]
if len(title) == 0:
title = "Empty Filename O_O"
titles.append(title)
titles = titles[1:]


tnurls = re.findall(r'(http://media.website.com/thumbs/\S{32}/\d+.jpg)', page)
vidurls = []
for url in tnurls:
url = re.sub('thumbs', 'videos', url)
url = re.sub('/\d+.jpg', '.mp4', url)
vidurls.append(url)
vidurls = uniquify(vidurls)


i = 0

for url in vidurls:
sleep(0.1)
if os.path.exists('downloaded.txt'):
f = open('downloaded.txt', 'r')
downloaded = f.read()
if re.search(url, downloaded):
i += 1
continue
j = 1
while os.path.exists(titles[i] + ".mp4"):
if j > 1:
titles[i] = titles[i][:-1]
titles[i] += str(j)
j += 1
filename = titles[i] + ".mp4"
while len(currentfiles) > 3:
sleep(0.1)
DlThread(url, filename).start()
i += 1
ParasitJonte
Profile Joined September 2004
Sweden1768 Posts
May 18 2011 20:29 GMT
#1074
On May 13 2011 02:03 Bobbias wrote:
Well its not like I have no experience at all. I was certainly planning on making a game as my final product, but I wanted to do more than just throw together a collection of hacks that somehow wind up creating a game. The purpose wasn't just to ind up with a game, but to really have learned some of the things I never got into learning when I was taking programming courses in high school (yeah, they weren't that serious, but by the end of it, I did have a fully functional 2D space invaders type game written in Java.)

All things considered I see this more as a way to learn more advanced coding practices, rather than an attempt just to make a game. It seems now that everyone makes games, but not everyone learns these advanced techniques.

So to sum things up a bit: The goal of this project is to learn some advanced game-making and programming concepts and to use them in an attempt to create a game.

I want to hard-code as little as possible into the game. Plus, anything I do hard code should be easily replaced with some other code or information (such as monster info loaded from an XML sheet).

I decided that I wanted the world to be open and non-linear because that means I don't actually need a storyline or quest system (although I'd like to add one).

C# provides quite a few tools to make various jobs easier (no need to write my own linked lists, no need to do detailed memory management, built in XML reading functionality) and I've downloaded the SDL.NET library to assist in the things that C# doesn't natively provide, so I'm not going to be totally re-inventing the wheel.


I understand where you're coming from.

First of all; I strongly recommend using XNA rather than SDL.NET. Not that SDL.NET isn't okay, but XNA is so much better and will make things so much easier for you.

Second of all; if you really want to do things good and if you're really more interested in producing quality code rather than just throwing together a game to show your friends, then aim for a very, very small project.

For example, if you wanted to make an RPG, considering instead just making a functional "fighting scene" game that could be a part of an RPG as a first project. Perhaps after that you can make a project that is just your character walking around a small village. Then you can refine and make it so you can enter houses or w-ever.

Whatever you do, don't aim for an actual game if you're just starting out. By the time you've invested 40+ hours you're going to have learnt a lot of new things, and you'll want to remake a lot of what you started out with.

Instead, just gradually increase the complexity of your projects and don't be afraid to start over (but of course, don't throw away your old code - some of it will be good and worth keeping).
Hello=)
ParasitJonte
Profile Joined September 2004
Sweden1768 Posts
May 18 2011 20:36 GMT
#1075
On May 19 2011 03:15 kerr0r wrote:
Okay, I have a problem. It involves python, threading and exceptions. The script grabs thumbnail urls from a video site and translates them into video urls to bypass the paywall. It then downloads the videos one at a time. I wanted to extend the script to include threading, so I could download more than one video at a time. Here's the problem though: It includes a cleanup function that deletes the incomplete file when closing. This works fine in the single-file, non-threaded version, but with threading it won't work. It seems to me that it tries to delete the files before closing the download threads, thus not being able to (since those files are already being used). Is there any way to make sure the threads are closed before the cleanup function executes?

Here's the code:
+ Show Spoiler +
import atexit
import threading
from time import sleep
import re
import urllib
import os.path
from os import remove

currentfiles = []

class DlThread(threading.Thread):
def __init__(self, url, filename):
self.url = url
self.filename = filename
threading.Thread.__init__(self)

def run(self):
currentfiles.append(self.filename)
print "Downloading " + self.filename + "..."
urllib.urlretrieve(self.url, self.filename)
print self.filename + " downloaded! "
f = open('downloaded.txt', 'a')
print >>f, self.url
currentfiles.remove(self.filename)
f.close()

def uniquify(seq, idfun=None):
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result

def cleanup():
for file in currentfiles:
remove(file)

atexit.register(cleanup)

for pn in range(192):
pn += 1
url = "http://www.website.com/most-viewed/page%s.html" % (pn)
f = urllib.urlopen(url)
page = f.read()
f.close()

titlesraw = re.findall(r'alt="[^"]*"', page)
titles = []
for title in titlesraw:
title = title[5:-1]
if len(title) == 0:
title = "Empty Filename O_O"
titles.append(title)
titles = titles[1:]


tnurls = re.findall(r'(http://media.website.com/thumbs/\S{32}/\d+.jpg)', page)
vidurls = []
for url in tnurls:
url = re.sub('thumbs', 'videos', url)
url = re.sub('/\d+.jpg', '.mp4', url)
vidurls.append(url)
vidurls = uniquify(vidurls)


i = 0

for url in vidurls:
sleep(0.1)
if os.path.exists('downloaded.txt'):
f = open('downloaded.txt', 'r')
downloaded = f.read()
if re.search(url, downloaded):
i += 1
continue
j = 1
while os.path.exists(titles[i] + ".mp4"):
if j > 1:
titles[i] = titles[i][:-1]
titles[i] += str(j)
j += 1
filename = titles[i] + ".mp4"
while len(currentfiles) > 3:
sleep(0.1)
DlThread(url, filename).start()
i += 1


What do you mean "the" incomplete file? It deletes files that are incomplete? Can't really understand your question.

However, what should be relevant to you is synchronization options. Why can't you just join all download threads (so you know that they've finished) before clean up?
Hello=)
DeCiBle
Profile Blog Joined December 2010
United States102 Posts
May 19 2011 05:00 GMT
#1076
I'm trying to append the contents of a string variable to the literal "II##" and assign it to a string in C++, so far I've gone in circles with every kind of temporary variable and conversion type.

basically I'm at:

contains += 1; //update the number of structures within the file
itemID = "II##";
itemID.append(contains.ToString());

but that's obviously not working; every simple solution seems to not exist. Is there any way to convert an interger to a string or put it in a file?

I've tried itemID = "II##" + contains.ToString();

and even just data << contains.ToString(); (where data is an fstream object)

I'm about to go kill. Help.
"You're a Scottish Noble Ribbon, and I am William fuckn Wallace" - ROOT.CatZ
heishe
Profile Blog Joined June 2009
Germany2284 Posts
May 19 2011 05:13 GMT
#1077
The "natural" way of converting datatypes to strings in C++ is the "stringstream" class (google it).

But the easier way would be to use boost::lexical_cast.

For a lack of time (have to go to university right this second), you'll have to google that as well. It's really simple though, you'll figure it out.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Greggle
Profile Joined June 2010
United States1131 Posts
May 19 2011 14:03 GMT
#1078
Hey guys, I hate to do this, but I've got an assignment due in a few hours. I wrote a C++ program in Dev-C++, and it compiles with no errors or warnings. The professor though always tests it by compiling it on linux with g++ though. I can't get my makefile to work for shit though.

The Dev-C++ makefile for windows is:
+ Show Spoiler +
# Project: lab7
# Makefile created by Dev-C++ 4.9.9.2

CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = main.o gstack.o gqueue.o $(RES)
LINKOBJ = main.o gstack.o gqueue.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib"
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = lab7.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before lab7.exe all-after


clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "lab7.exe" $(LIBS)

main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

gstack.o: gstack.cpp
$(CPP) -c gstack.cpp -o gstack.o $(CXXFLAGS)

gqueue.o: gqueue.cpp
$(CPP) -c gqueue.cpp -o gqueue.o $(CXXFLAGS)


The one I made for gcc in linux is (based on my extremely poor knowledge of makefiles):
+ Show Spoiler +
prog : main.cpp gqueue.o gqueue.h gstack.o gstack.h
g++ main.cpp -omain gqueue.o gstack.o
gqueue.o : gqueue.cpp gqueue.h
g++ gqueue.cpp -c
gstack.o : gstack.cpp gstack.h
g++ gstack.cpp -c


Can anyone help me translate it to Linux properly? They barely taught us anything about makefiles and I'm completely lost.
Life is too short to take it seriously.
astroorion
Profile Blog Joined September 2010
United States1022 Posts
May 22 2011 19:43 GMT
#1079
Does anyone know what code to put in to make a webpage figure out what browser you are using, if it's mobile, and then edit the webpage accordingly?
MLG Admin | Astro.631 NA
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
May 22 2011 19:50 GMT
#1080
On May 23 2011 04:43 astroorion wrote:
Does anyone know what code to put in to make a webpage figure out what browser you are using, if it's mobile, and then edit the webpage accordingly?

check the user agent http header field that the browser sends to your server in case you are working with a php/jsp/whatever thing that executes before the site is being sent. When working with javascript you'll need something else though. But google should be able to give you a bunch of hints on that.
Gold isn't everything in life... you need wood, too!
Prev 1 52 53 54 55 56 1032 Next
Please log in or register to reply.
Live Events Refresh
INu's Battles
11:00
INu's Battle #13
ByuN vs ZounLIVE!
IntoTheiNu 77
LiquipediaDiscussion
Replay Cast
10:00
LiuLi Cup #46 - Day 1
CranKy Ducklings240
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 503
sas.Sziky 9
StarCraft: Brood War
Britney 33936
Calm 11750
Hyuk 5297
Horang2 2799
Bisu 2665
GuemChi 1540
Flash 1435
Jaedong 1218
Larva 564
Soma 500
[ Show more ]
EffOrt 387
actioN 381
Mong 310
Light 288
Soulkey 272
Mini 253
Hyun 202
Snow 189
hero 151
Pusan 121
TY 104
JYJ84
Barracks 80
ggaemo 74
Killer 73
Mind 65
Sea.KH 61
JulyZerg 59
Aegong 50
Rush 38
Noble 35
ToSsGirL 28
Movie 27
sorry 26
Sharp 20
soO 19
scan(afreeca) 19
Sacsri 16
yabsab 16
Bale 13
SilentControl 11
Terrorterran 8
Shine 8
HiyA 7
Dota 2
Gorgc4990
qojqva2590
Dendi1040
XaKoH 505
420jenkins285
XcaliburYe217
Counter-Strike
olofmeister2883
x6flipin438
Heroes of the Storm
Khaldor206
Other Games
summit1g12066
singsing2411
B2W.Neo703
hiko613
Lowko296
Sick283
Pyrionflax251
Hui .125
Happy110
oskar71
Mew2King47
ToD25
Organizations
StarCraft: Brood War
lovetv 14
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 25
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis7636
Other Games
• WagamamaTV311
Upcoming Events
Monday Night Weeklies
2h 51m
Replay Cast
9h 51m
WardiTV Invitational
21h 51m
WardiTV Invitational
1d 1h
PiGosaur Monday
1d 10h
Replay Cast
1d 20h
Tenacious Turtle Tussle
2 days
The PondCast
2 days
OSC
2 days
WardiTV Invitational
3 days
[ Show More ]
Online Event
4 days
RSL Revival
4 days
RSL Revival
4 days
WardiTV Invitational
4 days
Afreeca Starleague
5 days
Snow vs Soma
Sparkling Tuna Cup
5 days
WardiTV Invitational
5 days
CrankTV Team League
5 days
RSL Revival
6 days
Wardi Open
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.