• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:17
CEST 12:17
KST 19:17
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL54Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
RECLAIM STOLEN BTC HIRE BLOCKCHAIN CYBER RETRIEVE Weekly Cups (June 23-29): Reynor in world title form? The SCII GOAT: A statistical Evaluation PiG Sty Festival #5: Playoffs Preview + Groups Recap The GOAT ranking of GOAT rankings
Tourneys
Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) RSL: Revival, a new crowdfunded tournament series [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
BW General Discussion Player “Jedi” cheat on CSL Flash Announces Hiatus From ASL BGH Auto Balance -> http://bghmmr.eu/ Unit and Spell Similarities
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Trading/Investing Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 748 users

The Big Programming Thread - Page 56

Forum Index > General Forum
Post a Reply
Prev 1 54 55 56 57 58 1031 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.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
May 25 2011 05:38 GMT
#1101
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I agree, the documentation suggests that it should return true.

I think a good start would be to override the default equals() implementation in the Position class with your own implementation and see if that works and if it even gets triggered. It looks to me as if it is not using the correct equals() method for some reason.
One Student
Profile Joined April 2011
73 Posts
Last Edited: 2011-05-25 05:41:00
May 25 2011 05:40 GMT
#1102
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I think the problem is with your equals() method. Check to see if you have correctly overwritten the Object class's equals method:

public boolean equals(Object obj){}

Using another equals(Position o) method will not suffice since the contains method will most likely use the Object class's equals method. So try that and do the necessary casting and see if it works.

EDIT: sorry guy above me I didn't see your post in time. ;p
Depression is what you get for leading a repetitive life.
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2011-05-25 05:49:08
May 25 2011 05:45 GMT
#1103
On May 25 2011 14:40 One Student wrote:
Show nested quote +
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I think the problem is with your equals() method. Check to see if you have correctly overwritten the Object class's equals method:

public boolean equals(Object obj){}

Using another equals(Position o) method will not suffice since the contains method will most likely use the Object class's equals method. So try that and do the necessary casting and see if it works.

EDIT: sorry guy above me I didn't see your post in time. ;p



did you override the default equals/hashCode? You must...

it'd help if you post your Position class

also, instead of getting the keyset, you can call

sons.containsKey( a );
When you want something, all the universe conspires in helping you to achieve it.
EpiK
Profile Blog Joined January 2007
Korea (South)5757 Posts
Last Edited: 2011-05-25 05:49:58
May 25 2011 05:45 GMT
#1104
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.
mr_tolkien
Profile Blog Joined June 2010
France8631 Posts
Last Edited: 2011-05-25 08:43:18
May 25 2011 08:40 GMT
#1105
Thank you for your answers, here is my equals function in Position :
+ Show Spoiler +
public boolean equals(Object o){
if(((Position)o).getX()==this.x && ((Position)o).getY()==this.y)
return true;
return false;
}

Seems to me like it's well coded.

I know of containsKey() btw, but the documentation isn't as clear as contains() for a Set, so for testing purposes I'm doing it with keySet.contains(). I'll change it once I'll sort this out.

EDIT : just figured it out ! I needed to cast b as an Object in my third line... Seems weird because there is no equals(Position) anyway, I was figuring he used the good one.
The legend of Darien lives on
ibutoss
Profile Blog Joined June 2005
Australia341 Posts
May 25 2011 09:02 GMT
#1106
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.
Nada got Yooned
mr_tolkien
Profile Blog Joined June 2010
France8631 Posts
Last Edited: 2011-05-25 09:17:35
May 25 2011 09:12 GMT
#1107
I'm back again, it was a wrong test I did, it still doesn't work the slightest \o/

I even did this :
sons.keySet().toArray()[0].equals(b)
Which returns TRUE.
And still, sons.containsKey(b) returns false.

I'm a bit in «WTFUUUUUUUUUUUUUUUUUUUUUUUUUUUU» mode right now, what I'm doing seems perfectly legit.

PS : I have a workaround working, but I'd like to know why it doesn't work in the first time.
The legend of Darien lives on
sdfno
Profile Joined March 2003
9 Posts
May 25 2011 10:13 GMT
#1108
I am guessin it's because you have overriden equals but not hashCode in your position class.
This means that Object.hashCode is used which explains why the first test is OK, but not the last one.

Here is an example of equals and hashCode for the Position Class:

+ Show Spoiler +

public class Main {
public static void main(String[] args) {

final HashSet<Position> positions = new HashSet<Position>();

final Position a = new Position(0, 0);
final Position b = new Position(0, 0);
positions.add(a);

System.out.println(positions.contains(a));
System.out.println(positions.contains(b));
}
}

class Position {
private int x;
private int y;

Position(int x, int y) {
this.x = x;
this.y = y;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Position position = (Position) o;

if (x != position.x) return false;
if (y != position.y) return false;

return true;
}

@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}

Tobberoth
Profile Joined August 2010
Sweden6375 Posts
May 25 2011 10:26 GMT
#1109
On May 25 2011 18:02 ibutoss wrote:
Show nested quote +
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.

I think it depends on the project. I work as a consultant to a very big swedish company on one of their web systems and there's no way a project like this would be done by freelancers since the system is huge and needs constant ongoing development, not only on the actual ASP.NET site but all the extra components, the databases and so on.

However, big companies generally have a lot of projects with very different scopes, I'm sure smaller ones could be done by freelancing smaller teams.
Seldon
Profile Joined March 2011
90 Posts
Last Edited: 2011-05-25 10:53:07
May 25 2011 10:51 GMT
#1110
On May 25 2011 18:02 ibutoss wrote:
Show nested quote +
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.


I agree if we are talking of a country like America (I don't know how Australia is in this regard). However I would like to add that if we are talking of Europe or a country with a worker-friendly labor code the situation is more in favor of freelancers. I see you are in Korea and I'm not sure what the situation is there but I'm under impression that it's more similar to Europe than to America.

In Europe in general it's getting really expensive to hire somebody due to social security, indemnifications you have to pay fired employees, the fact that if an employee gets pregnant you have to pay her while she takes a leave, the amount of bureaucratic BS that comes with employing every person, etc. Now I'm not saying this is good or bad, but it is a fact that it makes hiring more expensive and riskier.

Because of this contracting freelancers is incredibly attractive at the moment. You just pay for the work and none of the overheads cited above and if they don't deliver in time the contract is void and you don't have to pay. If an employee doesn't deliver in time... you are screwed and he isn't gonna return his paychecks.

So yeah, if what I explained above is true of the country you are in, I would say don't be afraid to go freelancer.
TheGiz
Profile Blog Joined October 2010
Canada708 Posts
Last Edited: 2011-05-25 18:17:33
May 25 2011 18:09 GMT
#1111
Hey, does anyone in this thread have experience with Excel?

I'm currently working on a super-huge Excel program at work (roughly 50-60 sheets and 20 modules) and I'm having some trouble with buttons. In a new workbook I am able to make a button and right-click on it to view its properties (i.e. Visible, Name, Caption, Background Colour, etc.). In the program though when I right-click to view the button's properties, I can't see the properties of the button I've selected - the Properties window is just blank. If I make a new button in the program the same thing happens.

Any idea what setting may have disabled my ability to view these properties?

EDIT: It just worked. Don't ask me how but it did. I'll edit this again if it keeps giving me problems.
Life is not about making due with what you have; it's about finding out just how much you can achieve. Never settle for anything less than the best. - - - Read my blog!
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2011-05-25 18:16:34
May 25 2011 18:15 GMT
#1112
On May 25 2011 17:40 mr_tolkien wrote:
Thank you for your answers, here is my equals function in Position :
+ Show Spoiler +
public boolean equals(Object o){
if(((Position)o).getX()==this.x && ((Position)o).getY()==this.y)
return true;
return false;
}

Seems to me like it's well coded.

I know of containsKey() btw, but the documentation isn't as clear as contains() for a Set, so for testing purposes I'm doing it with keySet.contains(). I'll change it once I'll sort this out.

EDIT : just figured it out ! I needed to cast b as an Object in my third line... Seems weird because there is no equals(Position) anyway, I was figuring he used the good one.


what about hashcode

it's not enough to only override equals

From a very high level, how a hashmap works is that
1) converts key object to number (this is what hashCode does)
2) put the value object in an array, position determined by the number obtained in 1.

You do not need to perform a cast when you call .equals(...), all objects in Java has the Object base class, so you can pass in Position objects just fine.

Also, your equals method is badly coded, you should use the .equals(...) that comes with your IDE and make modifications as you see fit.

For example, you don't check for null explicitly, and your .equals will throw an NPE if a null is passed in.
When you want something, all the universe conspires in helping you to achieve it.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2011-05-28 10:52:25
May 28 2011 10:32 GMT
#1113
Anyone here with GTK+ experience?

I've just started my adventure with it and I'm trying to figure out the basics but run into some problems already...

+ Show Spoiler [code] +


#include <gtk/gtk.h>
#include <stdlib.h>

#define STARTING_STAT 8;
#define STARTING_POOL 25;

char StatBuffer[5];

struct StatsConfig
{
gint8 StatStr;
gint8 StatDex;
gint8 StatCon;
gint8 StatInt;
gint8 StatWis;
gint8 StatCha;
gint8 StatPool;
};

struct StatsConfig* GetConfig();
int PoolIncrease(struct StatsConfig *config);
int PoolDecrease(struct StatsConfig *config);
int StrIncrease(struct StatsConfig *config);
int StrDecrease(struct StatsConfig *config);
void StrIncreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config);
void StrDecreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config);
void ReleaseMemory(struct StatsConfig *config);

int main(int argc, char** argv)
{
GtkWidget *window;
GtkWidget *frame;
GtkWidget *strPlusButton;
GtkWidget *strMinusButton;
GtkWidget *strLabel;
GtkWidget *poolLabel;
struct StatsConfig *config;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
frame = gtk_fixed_new();
strPlusButton = gtk_button_new_with_label("+");
strMinusButton = gtk_button_new_with_label("-");
strLabel = gtk_label_new("8");
poolLabel = gtk_label_new("25");
poolText = gtk_label_new("Stat point pool:");
strText = gtk_label_new("Str:");
config = GetConfig();

gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_title(GTK_WINDOW(window), "test");

gtk_container_add(GTK_CONTAINER(window), frame);

gtk_widget_set_size_request(strPlusButton, 25, 15);
gtk_fixed_put(GTK_FIXED(frame), strPlusButton, 5, 42);

gtk_widget_set_size_request(strMinusButton, 25, 15);
gtk_fixed_put(GTK_FIXED(frame), strMinusButton, 85, 42);

gtk_fixed_put(GTK_FIXED(frame), strLabel, 70, 40);
gtk_fixed_put(GTK_FIXED(frame), strText, 42, 40);

gtk_fixed_put(GTK_FIXED(frame), poolLabel, 200, 10);
gtk_fixed_put(GTK_FIXED(frame), poolText, 92, 10);

gtk_widget_show_all(window);

g_signal_connect(strPlusButton, "clicked",
G_CALLBACK(StrIncreaseButtonAction), strLabel);

g_signal_connect(strMinusButton, "clicked",
G_CALLBACK(StrDecreaseButtonAction), strLabel);

g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_main();

ReleaseMemory(config);

return 0;
}

struct StatsConfig* GetConfig()
{
gint8 statStr, statDex, statCon, statInt, statWis, statCha = STARTING_STAT;
gint8 statPool = STARTING_POOL;

struct StatsConfig *config;
config = malloc(sizeof(struct StatsConfig));

config->StatStr = statStr;
config->StatDex = statDex;
config->StatCon = statCon;
config->StatInt = statInt;
config->StatWis = statWis;
config->StatCha = statCha;
config->StatPool = statPool;

return config;
}

int PoolIncrease(struct StatsConfig *config)
{
return config->StatPool +1;
}

int PoolDecrease(struct StatsConfig *config)
{
gint8 statPool = config->StatPool;

if(statPool > 0)
{
return config->StatPool -1;
}

return config->StatPool;
}

int StrIncrease(struct StatsConfig *config)
{
gint8 statPool = config->StatPool;

if(statPool > 0)
{
PoolDecrease(config);

return config->StatStr +1;
}

return config->StatStr;
}

int StrDecrease(struct StatsConfig *config)
{
gint8 statStr = config->StatStr;

if(statStr > 3)
{
PoolIncrease(config);

return config->StatStr -1;
}

return config->StatStr;
}

void StrIncreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config)
{
StrIncrease(config);

sprintf(StatBuffer, "%d", config->StatStr);
gtk_label_set_text(strLabel, StatBuffer);

// sprintf(StatBuffer, "%d", config->StatPool);
// gtk_label_set_text(poolLabel, StatBuffer);
}

void StrDecreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config)
{
StrDecrease(config);

sprintf(StatBuffer, "%d", config->StatStr);
gtk_label_set_text(strLabel, StatBuffer);
}

void ReleaseMemory(struct StatsConfig *config)
{
if (config != NULL)
{
free(config);
config = NULL;
}
}



As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

Any tips?

P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.
Time is precious. Waste it wisely.
razzloss
Profile Joined October 2010
Finland4 Posts
Last Edited: 2011-05-28 12:56:55
May 28 2011 12:52 GMT
#1114
On May 28 2011 19:32 Manit0u wrote:
As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

Yes, I bet it does. In g_signal_connect you are passing a gtk_label as the data parameter for the signal handler, but in the handler itself you're trying to use the label as a struct StatsConfig*. Which obviously leads to problems. edit: Sorry read that wrong. It seems that the strlabel is used correctly in the signal handler. The problem is that the struct StatsConfig* probably contains garbage data as it isn't filled correctly.


For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

You can only pass one 'own' parameter to the handler. So if you want to change two or more labels in the same handler, you have to put them in to a struct/linked list/table and pass a pointer to that to the signal handler.



P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.

You shouldn't use gtk_fixed for anything. Instead use the other containers, (e.g. vbox/hbox) which place themselves automatically and react correctly to theme/window size changes.


thedeadhaji *
Profile Blog Joined January 2006
39489 Posts
May 28 2011 15:11 GMT
#1115
Couldn't really figure out how to properly set up the Google ap environment, so I decided to just set up a proper python environment and learn the language and get used to coding again before heading onto interface type stuff

Wish me luck!
jsmith
Profile Joined January 2011
United States18 Posts
May 28 2011 16:23 GMT
#1116
Hey guys I was wondering if anyone cold help me out with this question. I just graduated with my computer science degree the job I been at for a few months doesn't use my degree to much. I pretty much write SQL and do some database stuff. I wanna be able to stay fresh with other programming because I plan on either getting into the programming side of things with my company or move to another company that's more programming oriented. So, what would you guys suggest I do for some sort of recreational programming to help keep it fresh in my mind? Thanks!
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2011-05-28 17:42:43
May 28 2011 17:34 GMT
#1117
On May 28 2011 21:52 razzloss wrote:
Show nested quote +
On May 28 2011 19:32 Manit0u wrote:
As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

Yes, I bet it does. In g_signal_connect you are passing a gtk_label as the data parameter for the signal handler, but in the handler itself you're trying to use the label as a struct StatsConfig*. Which obviously leads to problems. edit: Sorry read that wrong. It seems that the strlabel is used correctly in the signal handler. The problem is that the struct StatsConfig* probably contains garbage data as it isn't filled correctly.

Show nested quote +

For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

You can only pass one 'own' parameter to the handler. So if you want to change two or more labels in the same handler, you have to put them in to a struct/linked list/table and pass a pointer to that to the signal handler.


Show nested quote +

P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.

You shouldn't use gtk_fixed for anything. Instead use the other containers, (e.g. vbox/hbox) which place themselves automatically and react correctly to theme/window size changes.




Thanks for the info. I've decided to scrap this thing allogether and write it from scratch, which led me to a ton of new problems...
I've decided to leave the buttons and operations on values for later and focused on getting my initial text to display in some more coherent way.

+ Show Spoiler [code] +


#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>

#define STARTING_STAT 8;
#define STARTING_POOL 25;

struct StatsConfig
{
gint8 StatStr;
gint8 StatDex;
gint8 StatCon;
gint8 StatInt;
gint8 StatWis;
gint8 StatCha;
gint8 StatPool;
};

char buffer[2];
struct StatsConfig* GetConfig();
char* ReturnStatPool(struct StatsConfig *config);
char* ReturnStats(struct StatsConfig *config);
char* ReturnStatNames();
void ReleaseMemory(struct StatsConfig *config);

int main(int argc, char** argv)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *label;
char *currentStats;
char *currentStatPool;
char *statNames;
struct StatsConfig *config;

config = GetConfig();
currentStatPool = ReturnStatPool(config);
statNames = ReturnStatNames();
currentStats = ReturnStats(config);

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_title(GTK_WINDOW(window), "Star Wars character builder");
gtk_container_set_border_width(GTK_CONTAINER(window), 5);

hbox = gtk_hbox_new(FALSE, 1);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);

frame = gtk_frame_new("Stat point pool:");
label = gtk_label_new(currentStatPool);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

hbox = gtk_hbox_new(FALSE, 1);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);

frame = gtk_frame_new("Name:");
label = gtk_label_new(statNames);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new("Value:");
label = gtk_label_new(currentStats);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

ReleaseMemory(config);

return 0;
}

struct StatsConfig* GetConfig()
{
gint8 statStr, statDex, statCon, statInt, statWis, statCha = STARTING_STAT;
gint8 statPool = STARTING_POOL;

struct StatsConfig *config;
config = malloc(sizeof(struct StatsConfig));

config->StatStr = statStr;
config->StatDex = statDex;
config->StatCon = statCon;
config->StatInt = statInt;
config->StatWis = statWis;
config->StatCha = statCha;
config->StatPool = statPool;

return config;
}

char* ReturnStatPool(struct StatsConfig *config)
{
int statPool = config->StatPool;

sprintf(buffer, "%d", statPool);

return buffer;
}

char* ReturnStats(struct StatsConfig *config)
{
int statStr = config->StatStr;
int statDex = config->StatDex;
int statCon = config->StatCon;
int statInt = config->StatInt;
int statWis = config->StatWis;
int statCha = config->StatCha;

char st1[50];
char st2[2];
char st3[2];
char st4[2];
char st5[2];
char st6[2];
char n = "\n";

sprintf(st1, "%d", statStr);
sprintf(st2, "%d", statDex);
sprintf(st3, "%d", statCon);
sprintf(st4, "%d", statInt);
sprintf(st5, "%d", statWis);
sprintf(st6, "%d", statCha);

strcat(st1, st2);
strcat(st1, n);
strcat(st1, st3);
strcat(st1, n);
strcat(st1, st4);
strcat(st1, n);
strcat(st1, st5);
strcat(st1, n);
strcat(st1, st6);

char* stats = st1;

return stats;
}


char* ReturnStatNames()
{
char* stats = "Strength\nDexterity\nConstitution\nIntelligence\nWisdom\nCharisma\n";

return stats;
}

void ReleaseMemory(struct StatsConfig *config)
{
if (config != NULL)
{
free(config);
config = NULL;
}
}



It was compiling and working fine up until I decided to add the stat values. The problem I'm facing (which is obvious from the code I believe) is that I have absolutely no idea how to make a concatenated string as a char array...

Here's an example of the problem I'm facing:

krs@chameleon:~/workspace/Gtk> gcc -std=c99 -o test test.c `pkg-config --libs --cflags gtk+-2.0`
test.c: In function ‘ReturnStats’:
test.c:132:11: warning: initialization makes integer from pointer without a cast
test.c:142:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:144:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:146:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:148:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’


Internet was no help to me so far
Time is precious. Waste it wisely.
kuresuti
Profile Blog Joined December 2009
1393 Posts
May 30 2011 11:05 GMT
#1118
On May 29 2011 02:34 Manit0u wrote:It was compiling and working fine up until I decided to add the stat values. The problem I'm facing (which is obvious from the code I believe) is that I have absolutely no idea how to make a concatenated string as a char array...


You could try making the string and converting it to a char array like so:


string a = "asd";

char* b = a.c_str();


Not sure if that's what you're asking for though

Good luck!


Tili_us
Profile Joined July 2010
Belgium44 Posts
May 30 2011 11:09 GMT
#1119
Hey guys, I love C++, but I can't ignore the handy stuff that C# gives.

Is there stuff like reflection c++? (maybe in the new version?)

Also, I've being working with Unity3D, and they use Coroutines using the yield command. Is this available in normal C# too ? (or even c++?)
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2011-05-30 15:16:56
May 30 2011 15:12 GMT
#1120
On May 29 2011 00:11 thedeadhaji wrote:
Couldn't really figure out how to properly set up the Google ap environment, so I decided to just set up a proper python environment and learn the language and get used to coding again before heading onto interface type stuff

Wish me luck!


That for web development?

I'm currently trying to get into this: http://www.symfony-project.org/

If you look for Python then go with Django: https://www.djangoproject.com/

P. S.

Disregard my previous post. After looking around I've decided to screw the C/Gtk+ for creating stuff with GUI and opted to go with C++/Qt instead. Gtk widget tree is such a bitch...
Time is precious. Waste it wisely.
Prev 1 54 55 56 57 58 1031 Next
Please log in or register to reply.
Live Events Refresh
RSL Revival
10:00
Season 1: Playoffs Day 3
ByuN vs ChamLIVE!
herO vs Reynor
Tasteless867
Crank 654
IndyStarCraft 64
Rex64
3DClanTV 47
IntoTheiNu 35
LiquipediaDiscussion
CranKy Ducklings
10:00
Master Swan Open #93
CranKy Ducklings16
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Tasteless 790
Crank 654
trigger 54
IndyStarCraft 49
Rex 49
StarCraft: Brood War
Larva 1064
Stork 330
Flash 312
actioN 182
Yoon 87
sorry 73
BeSt 66
Hyun 55
Last 44
Shinee 38
[ Show more ]
TY 31
Soulkey 29
Barracks 22
GoRush 22
Free 19
Mong 17
yabsab 14
NaDa 12
sSak 11
ivOry 6
SilentControl 4
Dota 2
XcaliburYe646
XaKoH 589
Counter-Strike
Stewie2K1320
Heroes of the Storm
Khaldor213
Other Games
Happy476
SortOf97
Organizations
StarCraft 2
ComeBackTV 300
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo2897
Upcoming Events
WardiTV European League
1h 43m
FEL
5h 43m
RSL Revival
23h 43m
Clem vs Classic
SHIN vs Cure
FEL
1d 1h
WardiTV European League
1d 1h
BSL: ProLeague
1d 7h
Dewalt vs Bonyth
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV European League
3 days
The PondCast
3 days
[ Show More ]
Replay Cast
4 days
RSL Revival
4 days
Replay Cast
5 days
RSL Revival
5 days
RSL Revival
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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
IEM Cologne 2025
FISSURE Playground #1
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.