• What do you need help with? Version 1
    5,001 replies, posted
This is what I got on the XML reading so far. It doesn't seem to work. [code] TiXmlDocument character( "character.xml" ); bool loadokay = character.LoadFile(); if (loadokay){ TiXmlElement *CharElement = character.FirstChildElement("currentmap"); spawn = *CharElement->Attribute("spawn"); maps.mapname = *CharElement->Attribute("map"); *CharElement = *CharElement->NextSiblingElement("coordinates"); charx = *CharElement->Attribute("x"); chary = *CharElement->Attribute("y"); mainch.fall = *CharElement->Attribute("fall"); mainch.jump = *CharElement->Attribute("jump"); *CharElement = *CharElement->NextSiblingElement("status"); hp = *CharElement->Attribute("hp"); maxhp = *CharElement->Attribute("maxhp"); mana = *CharElement->Attribute("mana"); maxmana = *CharElement->Attribute("maxmana"); }[/code] This is the XML file: [code]<?xml version="1.0" ?> <character> <currentmap spawn = "0" map = "map2.txt"/> <coordinates x = "633" y = "461" fall = "0" jump = "0" /> <status hp = "30" maxhp = "50" mana = "5" maxmana = "60" /> </character>[/code] The whole idea of this was so that I can easily create entries for inventory items that the character has, and so then the code will cycle through them. Anyway, it crashes with this error: Unhandled exception at 0x00f531b0 in SFML Game.exe: 0xC0000005: Access violation reading location 0x0000004c.
At which instruction/line does it crash? You also shouldn't blindly presume that none of these functions will return NULL.
It actually crashes at the TinyXML file [code]TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const { for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) { if ( strcmp( node->name.c_str(), name ) == 0 ) return node; } return 0; }[/code] And yeah I know I will build fail safes in after I get this running.
[QUOTE=eXeC64;25037413]I wouldn't consider this the work of a newbie programmer: [url]http://www.youtube.com/user/WolfireGames[/url][/QUOTE] Yes, but you have to remember that Lugaru was written a few years before Overgrowth. He's progressed a bit since then.
[QUOTE=WTF Nuke;25047743]Access violation reading location 0x0000004c.[/QUOTE] 0x4c is pretty near to 0x0, so it could be a NULL-pointer.
[QUOTE=ZeekyHBomb;25048426]0x4c is pretty near to 0x0, so it could be a NULL-pointer.[/QUOTE] 0x4C is also a capital letter in ASCII, so maybe cast from char to char*? Although most compilers would output a warning/error.
How can I access the VB.NET Web Browser control from one form to another, when it's being used in tabs? I'm trying to use it across another form to browse to the contents of a .txt file but I can't wrap my left nut around it..:v: I tried a simple thing that came to my head: [code] CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ListBox1.SelectedItem)[/code] And remembered that it was in another form, so I tried [code] Form1.CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ListBox1.SelectedItem)[/code] And gave me the errors: [code]'Form1' is not declared. It may be inaccessible due to its protection level. 'TabControl1' is not declared. It may be inaccessible due to its protection level. 'WebBrowser' is a type and cannot be used as an expression. [/code] And then I asked for help! (I recently went ~22 hours without sleep so I'm "recovering".)
How do you gt lua to run stand alone in linux? i cant seem to do it
[code]sudo apt-get install lua lua[/code] If you're on a Debian-based system.
I hate when commenting out a cout causes your program to behave differently. [editline]f[/editline] It appears this actually has a name: the Heisenbug. The program only has a bug when you stop printing out the inner working of that bug. [url]http://en.wikipedia.org/wiki/Heisenbug#Heisenbug[/url] [editline]f[/editline] Argh, multiple translation units suck. I want to get the assembly for the whole program, but it's giving me a separate one for each translation unit.
I need a little help getting started with x86 assembler and ruby.
[QUOTE=pkt;25081551]I need a little help getting started with x86 assembler and ruby.[/QUOTE] I'm going to assume you don't have much programming experience since you're asking, forgive me if you do. [url=http://mislav.uniqpath.com/poignant-guide/]Why's Poignant Guide to Ruby[/url] is a pretty good introductory book to Ruby if you have little programming experience. It's very different from most programming books though, so it's probably something you either love or hate. Why do you want to learn x86 assembly? It's a bit harder to learn than most languages as it's not widely used anymore. Chances are any books, tutorials or articles you'll find will be either very outdated or very technical, not really aimed at beginners.
[QUOTE=jA_cOp;25082507]Why do you want to learn assembly? It's a bit harder to learn than most languages as it's not widely used anymore.[/QUOTE] x86 assembly probably isn't used much outside of kernel work, but assembly languages in general are pretty widely used even still today. You have to remember that the number of PCs is very small in comparison to anything with an MCU/processor. Most computers are embedded systems.
[QUOTE=ROBO_DONUT;25082699]x86 assembly probably isn't used much outside of kernel work, but assembly languages in general are pretty widely used even still today. You have to remember that the number of PCs is very small in comparison to anything with an MCU/processor. Most computers are embedded systems.[/QUOTE] I'm referring to x86 assembly, which is what he's interested in.
[QUOTE=shill le 2nd;25081188]I hate when commenting out a cout causes your program to behave differently. [editline]f[/editline] It appears this actually has a name: the Heisenbug. The program only has a bug when you stop printing out the inner working of that bug. [URL]http://en.wikipedia.org/wiki/Heisenbug#Heisenbug[/URL] [editline]f[/editline] Argh, multiple translation units suck. I want to get the assembly for the whole program, but it's giving me a separate one for each translation unit.[/QUOTE] Sounds like you have memory errors. I've seen a few bugs like that, and after running my program through valgrind and fixing all the memory errors the bug went away.
Incoming noob questions, I've got a design problem that is probably easy to solve. This is c++ The public functions to access the grid of my minesweeper class isn't safe, for example: [cpp]std::vector<TileInfo> Grid; struct TileInfo { TileType Tile; FlagType Flag; bool Covered; }; enum TileType { Mine, Zero, One, Two, Three, Four, Five, Six, Seven, Eight }; TileType Minesweeper::GetTileType(unsigned X, unsigned int Y) { return Grid.at(X * GridWidth * Y).Tile; }[/cpp] Obviously I can stop it from accessing the vector easily, but I don't really know what to do then. It doesn't seem appropriate to add something to the tile class or enums and return one saying it doesn't exist, and I don't know how else to have these functions. It's not really the most relevant problem ever in this context. I can totally make sure i'm not going to use that function so it crashes, inside the class or out, but I want to know how to do it better.
[QUOTE=Pj The Dj;25083447]Incoming noob questions, I've got a design problem that is probably easy to solve. This is c++ The public functions to access the grid of my minesweeper class isn't safe, for example: Obviously I can stop it from accessing the vector easily, but I don't really know what to do then. It doesn't seem appropriate to add something to the tile class or enums and return one saying it doesn't exist, and I don't know how else to have these functions. It's not really the most relevant problem ever in this context. I can totally make sure i'm not going to use that function so it crashes, inside the class or out, but I want to know how to do it better.[/QUOTE] You mean if X and Y are larger than the vector? Look into exceptions if you haven't already. Though, when you use vector.at it already throws an exception if it's too large. Oh, and you probably want to do X+Y*GridWidth instead.
You should just add an extra TileType [i]Invalid[/i], which is returned when the passed grid position doesn't exist.
[QUOTE=noctune9;25084234]You mean if X and Y are larger than the vector? Look into exceptions if you haven't already. Though, when you use vector.at it already throws an exception if it's too large. Oh, and you probably want to do X+Y*GridWidth instead.[/QUOTE] Yeah. Also the two multiplications is a mistake. I typed it out in that post. Thanks for spotting that though. [QUOTE=Overv;25084264]You should just add an extra TileType [i]Invalid[/i], which is returned when the passed grid position doesn't exist.[/QUOTE] I know that works, but that would mean returning a tile that doesn't exist, which doesn't make sense to me. Does that make sense? Am I just over thinking it? Does none of this even matter at all? That was my solution though, I just don't feel like i'm learning anything by doing it.
If I were you, I'd leave it as it is and let it throw an exception if it's out of bounds.
[QUOTE=noctune9;25085272]If I were you, I'd leave it as it is and let it throw an exception if it's out of bounds.[/QUOTE] Yeah, as I see it.
The following code gives me this error: [code] Description Resource Path Location Type Duplicate parameter e capplet.java /commission_Applet/src line 59 Java Problem [/code] [code] catch (NumberFormatException e) { outputLabel.setText("You must enter a dollar amount greater than zero."); hiddenBox.setState(true); salesField.setText(""); salesField.requestFocus(); } [/code] How would I go about fixing it? I haven't had this problem before.
Sounds like it's telling you you've used the parameter name e in a parent block and you should choose a new one here.
[QUOTE=esalaka;25086833]Sounds like it's telling you you've used the parameter name e in a parent block and you should choose a new one here.[/QUOTE] Ah, I had used it before here: [code]public void itemStateChanged(ItemEvent e) {[/code]
Well I'm not that new to programming but I have a hard time finding resources. I choose x86 since I have a bunch of those lying around. My main problem with any language is finding decent tutorials for it all without FINDing books [free ones that the authors give away] or such. And I picked Ruby since I know python well enough that it seems a semi easy transition. I already know python, c++, javascript, html, bat, well enough to do what I need most of the time.
[QUOTE=PvtCupcakes;25083193]Sounds like you have memory errors. I've seen a few bugs like that, and after running my program through valgrind and fixing all the memory errors the bug went away.[/QUOTE] Yeah, the only difference in the assemblies was another pointer being pushed onto the stack, changing all the addresses. Thanks for suggesting valgrind; I was just trying to use GDB, and it's hopeless.
[QUOTE=noctune9;25085272]If I were you, I'd leave it as it is and let it throw an exception if it's out of bounds.[/QUOTE] I'd use assert. You'll get an error in debug-builds and none in release-builds. I use exceptions whenever the user can make something fail and assertions whenever I want to make sure that I don't do something wrong.
[QUOTE=pkt;25087990]warezing books or such.[/QUOTE] oh shit
[QUOTE=turb_;25088096]oh shit[/QUOTE] Fix'd ... Checking out that ruby book though it's funny that it's not the usual book though.
[QUOTE=Klownox;25087006]Ah, I had used it before here: [code]public void itemStateChanged(ItemEvent e) {[/code][/QUOTE] Okay, I'm having some more trouble. My program works pretty flawlessly, but there's one thing which is wrong. I run it and when I choose the "Outside Sales" option, it doesn't calculate the commission. Here's an example: [IMG]http://imgur.com/coE2K.png[/IMG] [IMG]http://imgur.com/UaH4y.png[/IMG] [IMG]http://imgur.com/WCoDn.png[/IMG] [code] import java.awt.*; import java.applet.*; import java.awt.event.*; import java.text.DecimalFormat; public class capplet extends Applet implements ItemListener { private static final long serialVersionUID = 1L; double dollars, answer; int empCode; Image dollarSign; Color darkRed = new Color(160, 50, 0); Label promptLabel = new Label( "Enter the sales amount(do not use commas or dollar signs):"); TextField salesField = new TextField(20); Label codeLabel = new Label("Select the appropriate commission code:"); CheckboxGroup codeGroup = new CheckboxGroup(); Checkbox telephoneBox = new Checkbox("Telephone Sales", false, codeGroup); Checkbox inStoreBox = new Checkbox("In-Store Sales", false, codeGroup); Checkbox outsideBox = new Checkbox("Outside", false, codeGroup); Checkbox hiddenBox = new Checkbox("", true, codeGroup); Label outputLabel = new Label( "Click an option button to calculate the sales commission."); public void init() { setBackground(darkRed); setForeground(Color.white); add(promptLabel); add(salesField); salesField.requestFocus(); salesField.setForeground(Color.black); add(codeLabel); add(telephoneBox); telephoneBox.addItemListener(this); add(inStoreBox); inStoreBox.addItemListener(this); add(outsideBox); add(outputLabel); } public void itemStateChanged(ItemEvent e) { try { dollars = getSales(); empCode = getCode(); answer = getComm(dollars, empCode); output(answer, dollars); } catch (NumberFormatException b) { outputLabel.setText("You must enter a dollar amount greater than zero."); hiddenBox.setState(true); salesField.setText(""); salesField.requestFocus(); } } public double getSales() { double sales = Double.parseDouble(salesField.getText()); if(sales <= 0) throw new NumberFormatException(); return sales; } public int getCode() { int code = 0; if(telephoneBox.getState()) code = 1; else if(inStoreBox.getState()) code = 2; else if(outsideBox.getState()) code = 3; return code; } public double getComm(double sales, int code) { double commission = 0.0; switch(code) { case 1: commission = .10 * sales; break; case 2: commission = .14 * sales; break; case 3: commission = .18 * sales; break; } return commission; } public void output(double commission, double sales) { DecimalFormat twoDigits = new DecimalFormat("$#,000.00"); outputLabel.setText("Your commission on sales of " + twoDigits.format(sales) + " is " + twoDigits.format(commission)); } /*public void paint(Graphics g) { dollarSign = getImage(getDocumentBase(), "d.jpg"); g.drawImage(dollarSign, 12, 28, this); }*/ } [/code]
Sorry, you need to Log In to post a reply to this thread.