• What do you need help with? Version 5
    5,752 replies, posted
I guess I need a bit of encouragement. I'm spending a lot of time on what appears to be really simple stuff. I forget variable names and sometimes try to call Classes themselves, and not instances when I do things. I've only been at it for a bit longer than a month, but will it get easier? At this point I'm wondering how the hell I would get to a level where simple 2d games were possible, but is that how a lot you felt, but you kept pushing?
i've been at it for two years and still feel stupid
[QUOTE=Zally13;39612350]I guess I need a bit of encouragement. I'm spending a lot of time on what appears to be really simple stuff. I forget variable names and sometimes try to call Classes themselves, and not instances when I do things. I've only been at it for a bit longer than a month, but will it get easier? At this point I'm wondering how the hell I would get to a level where simple 2d games were possible, but is that how a lot you felt, but you kept pushing?[/QUOTE] If you're forgetting variable names, perhaps you're using too many variables?
[QUOTE=Meatpuppet;39612305]game.h [cpp]#pragma once #include <SFML/Graphics.hpp> class game { public: sf::RenderWindow window; enum gameState { playing, paused }; gameState state; void launch(); void draw(); void isColliding(sf::RectangleShape shape); void increaseFieldSize(int size); void handleEvents(); bool isClosed(); }; static game GAME;[/cpp] GAME is used in main[/QUOTE] I wouldn't recommend doing that, because that will create your game class before main (as you've noticed) and there's no guarantee things are set up as expected or in any order if you have more static variables. I'm not sure what you're trying to achieve, but I would recommend doing it in the main.cpp instead, like this: [cpp] int main() { game GAME; GAME.launch(); while(!GAME.isClosed()) { GAME.handleEvents(); GAME.draw(); } return 0; }[/cpp] If you need to access game all over the place in other files for some reason, you should look into the singleton design pattern.
If you're forgetting variables names you've most likely not named them well. [editline]16th February 2013[/editline] [QUOTE=Robbis_1;39612429]If you need to access game all over the place in other files for some reason, you should look into the singleton design pattern.[/QUOTE] Or you could just design your application properly.
[QUOTE=Robbis_1;39612429]I wouldn't recommend doing that, because that will create your game class before main (as you've noticed) and there's no guarantee things are set up as expected or in any order if you have more static variables. I'm not sure what you're trying to achieve, but I would recommend doing it in the main.cpp instead, like this: [cpp] int main() { game GAME; GAME.launch(); while(!GAME.isClosed()) { GAME.handleEvents(); GAME.draw(); } return 0; }[/cpp] If you need to access game all over the place in other files for some reason, you should look into the singleton design pattern.[/QUOTE] Haha yes! That works! Thanks dude!
[QUOTE=dajoh;39612436]If you're forgetting variables names you've most likely not named them well. [editline]16th February 2013[/editline] Or you could just design your application properly.[/QUOTE] I totally agree on this, I don't like singletons myself, but if you're new to programming it's not obvious how it should be done.
Can anyone tell me how to make a simple fps counter with SFML 2.0? [editline]16th February 2013[/editline] also what are singletons
[QUOTE=Meatpuppet;39612869]Can anyone tell me how to make a simple fps counter with SFML 2.0?[/QUOTE] [cpp]sf::Clock frameClock; while(running) { float frameLength = frameClock.getElapsedTime().asSeconds(); // Frame rate is 1 / frameLength. frameClock.restart(); // Game logic. }[/cpp]
thanks!
[QUOTE=Meatpuppet;39612869]also what are singletons[/QUOTE] A singleton is a class that has only one instance which has a global point of access. Basically, it's implemented by making your constructor private, and having a static method that returns a reference to the one instance of the class (that method creates an instance if one doesn't already exist). It's usually used for classes that control an external resource, e.g. a database connection, assuming that you want to ensure that one connection is always used across the entire program.
[QUOTE=ShaunOfTheLive;39613668]A singleton is a class that has only one instance which has a global point of access. Basically, it's implemented by making your constructor private, and having a static method that returns a reference to the one instance of the class (that method creates an instance if one doesn't already exist). It's usually used for classes that control an external resource, e.g. a database connection, assuming that you want to ensure that one connection is always used across the entire program.[/QUOTE] I dont understand why its so bad if thats how you have designed your program/code?
Are there any ways of loading exceptionally large images into C# for System.Drawing? The program chokes when it reaches 1.5gb of memory. [editline]17th February 2013[/editline] Suppose I'll have to use something else huh?
[QUOTE=reevezy67;39614931]Are there any ways of loading exceptionally large images into C# for System.Drawing? The program chokes when it reaches 1.5gb of memory. [editline]17th February 2013[/editline] Suppose I'll have to use something else huh?[/QUOTE] What is it you are trying to do with these large images? For one generic idea, you could try splitting the image into smaller tiles and storing those instead of the whole.
I figured that's how I would have to do it.
I am trying to embed Lua into C++, but am running into troubles. Here are my current issues: [B]1.[/B] I want to load all the files in a folder rather than having to create a table and concat .lua to the values and do a dofile. Is there a way to do this? [B]2.[/B] I want each file to be an object, such as a weapon or ammo. How can I do this? I am currently just having them be loaded with dofile, then create an object of that type based on the values that are loaded in. I don't think this is the right way, because I am loading in global values this way. [B]3.[/B] I need to create something to hold these loaded weapons, because after 5 calls to the functions that the pointers point to become garbage collected. [B]Edit:[/B] I have solved 1, a bit, by installing lua file system. I am unsure how to open files that I get from the directory, but I'm further than I was. I have created a table for all the weapons that I load, which keeps them from getting erased, however the global value that I pass is getting erased, and giving me the error std::exception: 'Access violation - no RTTI data!'. Not sure what to do to fix this, I thought globals wouldn't get erased. How can I circumvent this? Still not sure on how to properly import things from files though. [B]Edit 2:[/B] Solving 1 solved 3 somehow, properly because it was the file that was being collected and not the global. Not sure though. I am still unsure how to properly load files, since from my understanding it imports everything from the dofile.
Anyone have experience with Django? Seems like a great new thing that job sites are FULL of people looking for. I already love Python, and I feel like it would be a way to get my foot in the door to a job, even if I have limited knowledge of it. Thoughts?
I have a small question regarding using git, I currently use Synkron to syncronize files between my usb, laptop and uni pc The way synkron works is it copies the newest version of a given file and replaces the previous version. I want to start using a local git repo for each of my big programming assignments but was wondering, if I delete files and then delete them in the repo(ie do a git add -A or git rm...) does that actually remove any physical files? or does it just remove the pointers? I ask as if it removes files then having synkron copy these back might mess it up
Add the --cache option when deleting your files, that should remove them from the repository, but not from the file system.
I'm trying to start a simple project with C# and monogame. If i try to do it in VS2012, i get a weird error if i try to create a monogame content project. If i do it in monodevelop, there isn't even an option for creating content projects so i dunno what i'd do. Why does monogame hate VS2012? Did i install monogame wrong or something?
[QUOTE=Gulen;39621570]Add the --cache option when deleting your files, that should remove them from the repository, but not from the file system.[/QUOTE] How do i do that when using the git add -A command? do i jut add --cache as well?
Not quite following you here... What are you trying to do? Do you want to add files that Synkron doesn't copy or what? Also, I think you're supposed to create a git repository somewhere else in your file system, so your files will always be in your "local" directory, even if you delete it from your repository (without --cache)
so basically synkron only copies files, it never deletes things. so if you delete something in a newer version of your filetree, then run synkron, the file will be back because synkron will copy it from the older version. What I was wondering is f I use git when modifying the repo via git add -A, does it delete anything within the .git folder?
No, not as far as I know. If you want git to delete those files that have been deleted on disk, you can do git add -u, or git add -u [path], if you don't want it to check your entire project for changes. Note that this'll add all the modifications you've done to your project, if you don't specify a path.
(Using Actionscript3) iv'e been trying to create a function in the document class that goes something like this: [code] function makeNewTurret(id:int):void { var classDefinition:String = "Turret_" + id.ToString(); // Add the numerical id as a prefix var tempClass:Class = flash.Utils.getDefinitionByName(classDefinition); var turret:Class = new tempClass(200,300); turretList.push(turret); addChild(displayObject(turret)); } [/CODE] where the class "Turret" has a constructor with arguments(X:int, Y:int), and extends MovieClip..(turret_1, turret_2 ect extend turret) when i call the function with id "1" for example (and Turret_1) exists i get the error [code] TypeError: Error #1034: Type Coercion failed: cannot convert Turret@2ce40201 to Class. at AngryBurgers_fla::MainTimeline/frame1() [/code] how can i make it, given - classes turret_1, _2 ect...extending class turret, - numerical id a function that creates a new instance of turret_prefix, and adds it to the display list.. (ps. interface ?? var turret:ITurret = new tempClass(200,300); ??)
[code] error: expected ‘)’ before ‘;’ token error: ‘i’ was not declared in this scope error: expected ‘;’ before ‘)’ token [/code] At the second while loop "while (int i = 0; i < phonebook.size(); i++)" It should work as if it was an array [i]i[/i] variable. Normally, these errors would mean I wrote something wrong somewhere, but I'm stumped this time. [cpp] #include <iostream> #include <fstream> #include <vector> #include "phonebookentry.h" using namespace std; int main() { string first, last, number; ifstream directory("phonebook.txt"); vector<phonebookentry> phonebook; while (directory >> first >> last >> number) { phonebookentry book(first, last, number); phonebook.push_back(book); } // End WHILE while (int i = 0; i < phonebook.size(); i++) { cout << phonebook[i].getFirst() << " " << phonebook[i].getLast() << endl << phonebook[i].getNumber() << endl << endl; } // End WHILE return 0; } // End MAIN [/cpp]
Shouldn't you be using a for loop instead of your last while loop?
[QUOTE=Gulen;39626072]Shouldn't you be using a for loop instead of your last while loop?[/QUOTE] W-whoops. Shame on me. Works exactly as it should changing that to a for. It's what I like about C++, where screwing up is your (well, mine) fault on logic.
[QUOTE=Stonecycle;39626212]W-whoops. Shame on me. Works exactly as it should changing that to a for. It's what I like about C++, where screwing up is your (well, mine) fault on logic.[/QUOTE] That wouldn't have worked in any language.
Can someone help me I'm working on a piglatin translator and here are the six cases [quote]//Look at Hw3cTester.java. It helps to specify much of the //behavior, through examples, of what should happen. It has //six cases: all lowercase letter words, words that can have //an uppercase letter as their first letter, and words that can //have punctuation at the start, end, or middle. (Punctuation //at the end stays at the end, and at the start stays at the //start. Punctuation in the middle stays where it is. It does //end any run of consonants to start a word, so d'dap -> 'dapday, //not apd'day. The last test case puts more stuff together. //The String returned should have one space between each word, //including after a sentence end, etc. and no leading or //trailing spaces. [/quote] [CODE]import java.util.Scanner; public class Hw3c { public static String e2PL(String input) { String[] words = input.split(" "); String output = ""; for(String word : words) { // Uppercase String pigLatin = word.toLowerCase(); if (word.charAt(0) == 'A' || word.charAt(0) == 'E' || word.charAt(0) == 'I' || word.charAt(0) == 'O' || word.charAt(0) == 'U') { pigLatin = Character.toUpperCase(pigLatin.charAt(0)) + pigLatin.substring(1) + "ay"; } else { pigLatin = pigLatin.substring(1) + pigLatin.toString()+ "ay"; } output += " " + pigLatin; } /* String in = ""; while(!in.equals("q")) { input = ""; for(int i = 1; i < in.length(); i++) input += in.charAt(i); input += in.charAt(0)+"ay"; } */ return output.trim(); } [/CODE] So I got this but i'm so darn confused because when it prints out the output It adds extra letters to the end not formatted as expected [code]public class Hw3cTester { public static void main(String[] args) { System.out.println("You may alway assume there is one space between any two words."); System.out.println("Six levels of functionality get you 12 points below./n"); String input = "you get two points for handling it with no uppercase or punctuation"; String output = Hw3c.e2PL(input); String expected = "ouyay etgay otway ointspay orfay andlinghay itay ithway onay uppercaseay oray unctuationpay"; System.out.println("Input: " + input); System.out.println("Output: " + output.toLowerCase()); System.out.println("Expected: " + expected.toLowerCase()); input = "Do Cases for Another two"; output = Hw3c.e2PL(input); expected = "Oday Asescay orfay Anotheray otway"; System.out.println("Input: " + input); System.out.println("Output: " + output); System.out.println("Expected: " + expected); input = "end of word punctuation!! for two more."; output = Hw3c.e2PL(input); expected = "enday ofay ordway unctuationpay!! orfay otway oremay."; System.out.println("Input: " + input); System.out.println("Output: " + output); System.out.println("Expected: " + expected); input = "'twas two more for start of word 'unctuation"; output = Hw3c.e2PL(input); expected = "'astway otway oremay orfay artstay ofay ordway 'unctuationay"; System.out.println("Input: " + input); System.out.println("Output: " + output); System.out.println("Expected: " + expected); input = "don't forget within a word m'kay"; output = Hw3c.e2PL(input); expected = "on'tday orgetfay ithinway aay ordway 'kaymay"; System.out.println("Input: " + input); System.out.println("Output: " + output); System.out.println("Expected: " + expected); input = "If you want to sleep in, don't!! Get-r-going early."; output = Hw3c.e2PL(input); expected = "Ifay ouyay antway otay eepslay inay, on'tday!! Et-r-goinggay earlyay."; System.out.println("Input: " + input); System.out.println("Output: " + output); System.out.println("Expected: " + expected); } }[[/code] HOW SHOULD I APPROACH THIS?
Sorry, you need to Log In to post a reply to this thread.