Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 66 67 [68] 69 70 ... 91

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

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1005 on: January 11, 2013, 07:38:33 pm »

Your problem is that the variable holding your metaDataContainer object is also called metaDataContainer. This makes the interpreter think that you're trying to call the function on the class, not on the specific object. It should work if you give it another name.
just took a look at it and you are declaring the variable but not initializing it.
you might want to do
Code: [Select]
var metaDataSave : metaDataContainer = new metaDataContainer();
metaDataSave.Save(Path.Combine(Application.dataPath, "Campaigns/" + title + "/meta.xml"));

Not initializing the metaDataSave variable is causing it to hold a null-value, and so you get a null reference exception when you try to do anything with it :P

Virex, GalenEvil, you two are lifesavers.

It works, but the XML file has only this in it:
Code: [Select]
<?xml version="1.0" encoding="Windows-1252"?>
<meta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

I've tried finagling with setting the variable title to titleClass.title with titleClass being of the type metaTitle, like the class that shares the name metaTitle. I assume the serializer isn't writing any data to the file because public var metaData : System.Collections.Generic.List.<metaTitle>; has no data stored in it, but I'm unsure how to set the list to include title in it.

EDIT: Okay, finally got it to work! Turns out I was messing up with public var metaData : System.Collections.Generic.List.<metaTitle>;, and it should have been public var metaData : List.<metaTitle> = List.<metaTitle>();.

EDITEDIT: Nope, but I'm a step ahead of where I was. I have it exporting without actually saving the campaign title.

Code: [Select]
#pragma strict

import System.Collections.Generic;
import System.Xml;
import System.Xml.Serialization;
import System.IO;

public var skin : GUISkin;

private var titleWarning : boolean = false;
private var campaignExists : boolean = false;

public class metaTitle {
public var title : String;
}

public var titleVar : metaTitle = new metaTitle();
titleVar.title = "New Campaign";

@XmlRoot("meta")
public class metaDataContainer {
@XmlArray("metaData")
@XmlArrayItem("metaTitle")
public var metaData : List.<metaTitle> = List.<metaTitle>();

public function Save (path : String) {
var serializer : XmlSerializer = new XmlSerializer(typeof(metaDataContainer));
var stream : Stream = new FileStream(path, FileMode.Create);
serializer.Serialize(stream, this);
stream.Close();
}

public static function Load (path : String) : metaDataContainer {
var serializer : XmlSerializer = new XmlSerializer(metaDataContainer);
var stream : Stream = new FileStream(path, FileMode.Open);
var result : metaDataContainer = serializer.Deserialize(stream) as metaDataContainer;
stream.Close();
return result;
}
}

function OnGUI () {
GUI.skin = skin;

titleVar.title = GUI.TextField(Rect(Screen.width * .75 - 60, Screen.height * .5 - 10, 120, 20), titleVar.title);
GUI.Box(Rect(Screen.width * .75 - 50, Screen.height * .5 + 10, 100, 20), "Campaign Title");

if (GUI.Button(Rect(Screen.width * .75 - 100, Screen.height * .65 - 30, 200, 60), "Create Campaign")) {
if (titleVar.title == "") {
titleWarning = true;
}
else if (System.IO.Directory.Exists("Campaigns/" + titleVar.title)) {
titleWarning = false;
campaignExists = true;
}
else {
System.IO.Directory.CreateDirectory("Campaigns/" + titleVar.title);
var metaDataSave : metaDataContainer = new metaDataContainer();
meta.Save(Path.Combine(Application.dataPath, "../Campaigns/" + titleVar.title + "/meta.xml"));
}
}

if (titleWarning) {
GUI.Box(Rect(Screen.width * .75 - 80, Screen.height * .75 - 20, 160, 40), "Enter campaign title!");
}
if (campaignExists) {
GUI.Box(Rect(Screen.width * .75 - 80, Screen.height * .75 - 20, 160, 40), "Campaign already exists!");
}
}

So... as far as I can tell, the problem is that public var metaData : List.<metaTitle> = List.<metaTitle>(); never has values put into it from public var titleVar : metaTitle = new metaTitle();.

I'm seriously lost now. Is there a way to add information to the List that I'm missing?
« Last Edit: January 12, 2013, 12:23:26 am by Araph »
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1006 on: January 12, 2013, 12:01:34 am »

So, I program in C++, and I only know SDL, i'm a good way into making a game, and I was wondering if it was worth it continuing work on this, or if I should stop and learn OpenGL before continuing,
I mean, SDL is working fine for me, working on learning SDL's multithreading and getting this program threaded. 
it should be easy to upgrade it to OpenGL if I end up needing to, right?  I mean it's just a change in the way it draws to the screen, right? or what..
any opinions on the matter?

Also, anyone have any suggestions for how to learn OpenGL, i've tried tackling it twice so far, both times didn't end well for me.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1007 on: January 12, 2013, 01:43:03 am »

I believe OpenGL is very different from SDL. OpenGL is for drawing things, such as shapes, polygons, 3D models... while SDL is simply for displaying them, and catching input, and doing output.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Programming Help Thread (For Dummies)
« Reply #1008 on: January 12, 2013, 05:51:10 am »

@Araph: You may need to specify how you want to serialize the data, or that it's even serializable. I haven't worked with XML serialization though, and it's just a little late (4:49am current) for me to be attempting to learn it at the moment. I'll poke at it when I wake up and will report any findings if the question hasn't been answered already :P
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1009 on: January 12, 2013, 12:11:56 pm »

Also, anyone have any suggestions for how to learn OpenGL, i've tried tackling it twice so far, both times didn't end well for me.

Look up nehe's opengl tutorials, they are old and probably too slow paced if your already coding a game but they cover most things from the basics up and if you can bare following from the start to end should give you a good grounding.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

JanusTwoface

  • Bay Watcher
  • murbleblarg
    • View Profile
    • jverkamp.com
Re: Programming Help Thread (For Dummies)
« Reply #1010 on: January 12, 2013, 12:57:52 pm »

So, I program in C++, and I only know SDL, i'm a good way into making a game, and I was wondering if it was worth it continuing work on this, or if I should stop and learn OpenGL before continuing,
...
Since you're already working with C++, allow me to suggest SFML. Unlike SDL or OpenGL, it was written for C++ rather than C so you get a nice object oriented API. Plus it uses OpenGL for the backend so you get 3d acceleration and can more easily transition later. There are fewer tutorials than for the others just because it's a younger project, but I still think there's enough.
Logged
You may think I'm crazy / And I think you may be right
But life is ever so much more fun / If you are the crazy one

My blog: Photography, Programming, Writing
Novels: A Sea of Stars, Confession

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1011 on: January 12, 2013, 01:10:29 pm »

So, I program in C++, and I only know SDL, i'm a good way into making a game, and I was wondering if it was worth it continuing work on this, or if I should stop and learn OpenGL before continuing,
...
Since you're already working with C++, allow me to suggest SFML. Unlike SDL or OpenGL, it was written for C++ rather than C so you get a nice object oriented API. Plus it uses OpenGL for the backend so you get 3d acceleration and can more easily transition later. There are fewer tutorials than for the others just because it's a younger project, but I still think there's enough.
Seconded, but you still need to learn OpenGL. If you don't want to learn that, use a 3D engine like Ogre3D or Irrlicht.
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))

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1012 on: January 12, 2013, 02:08:07 pm »

The main thing I'm planning on doing with, openGL is 2D games, so ogre and irrlicht are both out of the question.  And since I've been working with SDL for so long I'm not sure if I want to switch to SFML, but I'll check it out.  Thanks for the tutorial suggestion shades, I'll check that out as well.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1013 on: January 12, 2013, 04:01:21 pm »

Code: [Select]
public var metaData : List.<metaTitle> = new List.<metaTitle>();

There must be a way to add some value into a list, but Google has been silent on the matter. I've tried using other variable types and... they... work...

...Wait.

Code: [Select]
@XmlArrayItem("title")
public var title : String = titleVar;

The only problem with this is that Unity gives the error Unknown identifier: 'titleVar' despite me having already declared the variable at the beginning of the script. This is probably just another example of my ignorance of classes showing, but is there a reason why the script wouldn't recognize a variable like that?

EDIT:
Code: [Select]
@XmlArrayItem("title")
public var title : String = campaignCreationGUI.titleVar;

HUZZAH! IT WORKS!
« Last Edit: January 12, 2013, 06:46:54 pm by Araph »
Logged

AlStar

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1014 on: February 18, 2013, 02:55:48 am »

Hey, I'm sure that there's an easy answer to this, but I've been hitting a wall for at least the last half hour here and some quick googling doesn't seem to be helping.

Ok, so this is in Java.

The code is trying to place orders on a market. This snippet of code, in particular, is working with food. Where I'm running into problems is that, with food, the entity needs to reserve some food for itself, then place the extra on the market. I'm doing this by using System.arraycopy on the food item to double it, then adjusting the number of items in each pile of food (so that the total number of items remains the same) and then sending the food that's not being eaten to market.

The problem is that the two food items are linked, so any change in one effects the other. This is confusing me because I thought that System.arraycopy should create unique objects.

Am I using the wrong tool for the job (other than programming in Java  :P ), or did I mess up somewhere?

note: I've already checked that x and usedthings are different, so that's not the problem.

Spoiler (click to show/hide)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1015 on: February 18, 2013, 03:14:50 am »

I think what's happening here is that System.arraycopy will only copy the class handles (or references or whatever Java calls the things that only refer to class instances) and not perform a deep copy of the objects. I don't know how you would do this in Java unfortunately.
Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1016 on: February 18, 2013, 04:37:02 am »

Javas clone method is broken.
Create a copy constructor, and create a new cloned array yourself.
Logged
Merchants Quest me programming a trading game with roguelike elements.

Urist_McArathos

  • Bay Watcher
  • Nobody enjoys a good laugh more than I do.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1017 on: February 22, 2013, 01:30:11 pm »

Hey, having a hard time coding a button for python (and pygame).

Here's my attempt thus far at the code:

Spoiler (click to show/hide)

My goal was to save this file, and import it into my main code, and then be able to define a button using any given font and image I like, on any given x,y point (centered on that point, but I can switch it to topleft without much hassle).  It doesn't seem to work when I try it, though.

Here's a sample code you guys can see how I'm trying to make it work.

Spoiler (click to show/hide)


Logged
Current Community/Story Projects:
On the Nature of Dwarves

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1018 on: February 22, 2013, 02:02:12 pm »

I have something that is almost like buttons. It's more like a text menu at the moment, though, but now that I've read your post I may update it to be button-oriented.

It's currently keyboard-driven, but it should be fairly easy to add mouse support.

Code here
In all likelihood, you won't be able to run my project. Python 3, Pygame, PyYAML, and possibly some other third-party modules.

I haven't done any work for a week, but after thinking about nothing but my project for a long time, I've gotten a little burned out.
« Last Edit: February 22, 2013, 02:03:44 pm by Mephisto »
Logged

Urist_McArathos

  • Bay Watcher
  • Nobody enjoys a good laugh more than I do.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1019 on: February 23, 2013, 01:54:46 am »

See, here's where my true novice colors are showing: what's with all that self stuff in your code?  Like all the self.whatevers and so on.
Logged
Current Community/Story Projects:
On the Nature of Dwarves
Pages: 1 ... 66 67 [68] 69 70 ... 91