• What Do You Need Help With? V6
    7,544 replies, posted
The main() function is not in any class, it's just the entry point. I have no idea why me from 6 months ago did this but it surely is poorly designed. I'm thinking of moving the entire code in the previously mentioned 'game' class so I have something like this (just a sketch): [code] class Game { level l1; player p1; //probably use a vector for those two so I can easily add players/create new levels public: //... void gameLoop(); void update(); void draw(); int getBlockAt(int playerPosX, int playerPosY); } [/code] But again, the colision is handled by a third party and is not a direct communication between player->level.
Does anyone know how to change the tab-ordering within a QTreeWidget in Qt4? I have A QTreeWidget with three columns and a bunch of items and want the Tab key to move column to column (left to right) and then when it reaches the final column jump to the next item (top to bottom). Default: [code] [1][ ][ ] [2][ ][ ] [3][ ][ ] [/code] Desired: [code] [1][2][3] [4][5][6] [7][8][9] [/code] If this isn't an option, what is the most sane way to go about trapping the Tab key to implement this myself?
I'm just trying to mess around with stuff in C++, so I've designed a login menu, and I want to know which way would be the best one to check if the input is right (Username and password through a website).
Well, you'd have to send a POST request to the webserver's login page, and check the result. I'd probably use a JSON format for the result, like the Facepunch API does.
[QUOTE=ThePuska;40209749][cpp]char rot13(char c) { if (c >= 'a' && c <= 'z') c = 'a' + ((c - 'a') + 13) % 26; else if (c >= 'A' && c <= 'Z') c = 'A' + ((c - 'A') + 13) % 26; return c; }[/cpp][/QUOTE] After messing around with this, I've come the conclusion that I don't understand why you're doing c-'A'/c-'a'. I wrote it like this: [cpp] char rot13(char c) { if (c >= 'a' && c <= 'z') c = ((c + 13) % 26) + 'a'; else c = ((c + 13) % 26) + 'A'; return c; } [/cpp] and it worked fine for me...do the encryption and then offset your result to start wherever your lower bound starts (a or A). I have no idea why you did "((c-'A') + 13) % 26". What's the purpose of c-'A'?
Can I use for_each with a vector of object pointers? Seems to only work with int for me.
[QUOTE=Asgard;40234647]Can I use for_each with a vector of object pointers? Seems to only work with int for me.[/QUOTE] You can use for_each on any sequence with input iterators, so yes.
[QUOTE=Zinayzen;40234034]After messing around with this, I've come the conclusion that I don't understand why you're doing c-'A'/c-'a'. I wrote it like this: [cpp] char rot13(char c) { if (c >= 'a' && c <= 'z') c = ((c + 13) % 26) + 'a'; else c = ((c + 13) % 26) + 'A'; return c; } [/cpp] and it worked fine for me...do the encryption and then offset your result to start wherever your lower bound starts (a or A). I have no idea why you did "((c-'A') + 13) % 26". What's the purpose of c-'A'?[/QUOTE] Your code doesn't work. It doesn't do anything to upper case letters and lower case letters are rotated by 6. Here are the three steps that the algorithm does, commented: [cpp]char c0 = c - 'a'; // Convert lower-case alphabet from ASCII to integers in the range 0..26 char c1 = (c0 + 13) % 26; // Rotate the integers by 13 char c2 = c1 + 'a'; // Convert integers from range 0..26 to ASCII[/cpp]
...why does mine only rotate by six? It looks like it would work... I'm trying to get used to writing the algorithms by myself, and I clearly need more practice. [editline]10th April 2013[/editline] OH i get it now. how the fuck would I have figured that out by myself? It's super simple but totally not something I've learned to pay attention to.
[QUOTE=Gulen;40198175]Flash is a fairly good place to learn to make games, I guess, but since you already know Java, I'd recommend you work on that instead. [URL="http://zetcode.com/tutorials/javagamestutorial/"]This [/URL]is where I learnt to make games, and I think it's a pretty good tutorial.[/QUOTE] Why learn an entirely new language when he already knows Java? [url]http://www.lwjgl.org/[/url]
-snip- i suddenly magically remembered stuff.
So! I'm programming in Java, trying to do a "where's waldo"-y kind of thing. I have a small image (say 10x10) and I want to be able to find it in a bigger image in terms of returning coordinates. This image will not be scaled or rotated at all. Is there a pre-made library I can use or would I have to make something myself?
[QUOTE=Larikang;40236431]Why learn an entirely new language when he already knows Java? [url]http://www.lwjgl.org/[/url][/QUOTE] That is exactly what I told him...
I have a vector that looks like this: std::vector< std::vector<Tile*> > map; and I try to iterate over it in TileManager::DrawMap() with the following: for_each( map.begin(), map.end(), []( int& i ) { std::cout << "hi" << std::endl;} ); Why does this throw the error: [code] Error 7 error C2664: 'void TileManager::DrawMap::<lambda_7fdaeb74f0d4f623f4d50905d6753191>::operator ()(int &) const' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'int &' [/code] I assume it's confused because of the nested vector?
well if you make the lambda take an int as parameter instead of the vector<Tile *> it has all right to be confused. try []( std::vector<Tile *>& i ) { std::cout << "hi" << std::endl;}
:downs:
What are these things called and what do they do? [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2013-04/whatisthis.png[/IMG] [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2013-04/whatisthis2.png[/IMG]
It's inheritance. SaveData inherits MonoBehaviour; MonoBehaviour is its ancestor class. It means that every instance of SaveData is also an instance of MonoBehaviour - it gets all the same fields and methods.
[QUOTE=Pelf;40250825]What are these things called and what do they do? [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2013-04/whatisthis.png[/IMG] [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2013-04/whatisthis2.png[/IMG][/QUOTE] Looks like inheriting to me, but I'm not sure as I'm only familiar with Java. [editline]12th April 2013[/editline] Derp late
Trying to make a silly telephone word combination generator for an assignment here (Java). Think I almost have it with some recursion, but it's throwing stack overflow exceptions starting at the switch in getChar, then setting out[depth], and then the rest is stuck at the crackCode recursion point. What am I doing wrong here? [code]package telephoneletters; // Here be imports import java.util.Scanner; public class TelephoneLetters { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Punch in a phone number..."); String telenum = input.nextLine(); char[] out = new char[telenum.length()]; crackCode(string2IntArray(telenum), out, 0); } public static void crackCode(int[] numero, char[] out, int depth){ if(depth==numero.length){ //base case in recursion System.out.println(out); return; } for(int i = 1; i <= 4; i++){ //recursive case in recursion if(i == 4 && (numero[depth] != 7 && numero[depth] != 9)) continue; out[depth] = getChar(numero[depth],i) ; crackCode(numero, out, depth+1); } } public static int[] string2IntArray(String st) { char[] stc = st.toCharArray(); int[] sti = new int[stc.length]; int counter = 0; for (char c : stc) { sti[counter] = c; counter++; } // End FOR (Trying to find help for these things online, I never knew this was a valid FOR.) return sti; } public static char getChar(int numero, int depth){ switch(numero){ case 2: if(depth==1) return 'a'; else if(depth==2) return 'b'; else if(depth==3) return 'c'; else return 0; case 3: if(depth==1) return 'd'; else if(depth==2) return 'e'; else if(depth==3) return 'f'; else return 0; case 4: if(depth==1) return 'g'; else if(depth==2) return 'h'; else if(depth==3) return 'i'; else return 0; case 5: if(depth==1) return 'j'; else if(depth==2) return 'k'; else if(depth==3) return 'l'; else return 0; case 6: if(depth==1) return 'm'; else if(depth==2) return 'n'; else if(depth==3) return 'o'; else return 0; case 7: if(depth==1) return 'p'; else if(depth==2) return 'q'; else if(depth==3) return 'r'; else return 's'; case 8: if(depth==1) return 't'; else if(depth==2) return 'u'; else if(depth==3) return 'v'; else return 0; case 9: if(depth==1) return 'w'; else if(depth==2) return 'x'; else if(depth==3) return 'y'; else return 'z'; default:break; } return 0; } }[/code] [editline]wewqe[/editline] Changed the increment from ++ to +1 in the recursive crackCode function, but now it's outputting spaces.
I want some sort of list, where I can display a list of a class (with two strings and one int). How do I do this? The idea is that I write these three variables in a textbox and then you get these into the list by clicking a button "Add". [I](This is C#).[/I]
[QUOTE=JohanGS;40253835]I want some sort of list, where I can display a list of a class (with two strings and one int). How do I do this? The idea is that I write these three variables in a textbox and then you get these into the list by clicking a button "Add". [I](This is C#).[/I][/QUOTE] I don't fully understand your question, but it would be something along these lines: [code] public class MyClass { public String String1; public String String2; public int Int1; public MyClass(String String1, String String2, int Int1) { this.String1 = String1; this.String2 = String2; this.Int1 = Int1; } } public class Form1 { .. your other code .. private List<MyClass> _listOfThings = new List<MyClass>(); private void OnButtonClick() { _listOfThings.Add(new MyClass(_textBox1.Text, _textBox2.Text, _numericBox3.Value); } } [/code] [editline]12th April 2013[/editline] Or do you mean list as in form control, not the data type? If that's the case, make a listbox and then call this code on the button click: [code] _listBox1.Items.Add(String.Format("{0} {1} {2}",_textBox1.Text, _textBox2.Text, _numericBox3.Value)); [/code]
hey everyone, i am currently a begginer with C# and i am trying to do a simple application where i write the answer to 2+2 where i'd like it to say, if its 4, to note its correct, if its 10, to say its correct in base 4, and any other answer to note that its wrong, doing this just to learn more [IMG]http://i.imgur.com/zfoEpaR.png?1?7975[/IMG] This is the code [code]using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "4") MessageBox.Show("Right answer"); else if (textBox1.Text != "4") MessageBox.Show("Nope, wrong answer"); else (textBox1.Text == "10"); MessageBox.Show("In base 4, yes, else, nope, wrong"); } } } [/code] [editline]sdfas[/editline] I am not sure where i screwed up, if someone knows where i fucked up, please point it out to me, thanks. [QUOTE=eternalflamez;40254328]EDIT: okay, what is the error?[/QUOTE] It does not let me compile it :v: Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
I don't think you actually asked a question.
[QUOTE=DatGman;40254298]hey everyone, i am currently a begginer with C# and i am trying to do a simple application where i write the answer to 2+2 where i'd like it to say, if its 4, to note its correct, if its 10, to say its correct in base 4, and any other answer to note that its wrong, doing this just to learn more [img]http://i.imgur.com/zfoEpaR.png?1?7975[/img] This is the code /code] Thanks[/QUOTE] EDIT: okay, what is the error? [editline]12th April 2013[/editline] Found it: else (textBox1.Text == "10"); MessageBox.Show("In base 4, yes, else, nope, wrong"); Change to else if (textBox1.Text == "10") MessageBox.Show("In base 4, yes, else, nope, wrong");
[QUOTE=eternalflamez;40254328]EDIT: okay, what is the error? [editline]12th April 2013[/editline] Found it: else (textBox1.Text == "10"); Remove the ';'[/QUOTE] Now upon compilation it says "; expected" :v: [editline]sfasf[/editline] Now it does compile, but when i write "10" in there it says its wrong answer
[QUOTE=DatGman;40254362]Now upon compilation it says "; expected" :v:[/QUOTE] Edited accordingly ^^ [editline]12th April 2013[/editline] Other than that, your order in if statements is wrong: [code] if (textBox1.Text == "4") { MessageBox.Show("Right answer"); } else if (textBox1.Text != "4") { MessageBox.Show("Nope, wrong answer"); } else if (textBox1.Text == "10") { MessageBox.Show("In base 4, yes, else, nope, wrong"); } [/code] If its 4, it says it's good, then if it's not 4, it'll say you are wrong. It never goes into the third statement. [code] if (textBox1.Text == "4") { MessageBox.Show("Right answer"); } else if (textBox1.Text == "10") { MessageBox.Show("In base 4, yes, else, nope, wrong"); } else { MessageBox.Show("Nope, wrong answer"); } [/code] Works better. (Added brackets but it does not really matter, it's just how I work) [editline]12th April 2013[/editline] [QUOTE=DatGman;40254362]Now upon compilation it says "; expected" :v: [editline]sfasf[/editline] Now it does compile, but when i write "10" in there it says its wrong answer[/QUOTE] Haha I can't seem to post the solution faster than you post new problems :v:
[QUOTE=eternalflamez;40254364]Edited accordingly ^^ [editline]12th April 2013[/editline] Other than that, your order in if statements is wrong: [code] if (textBox1.Text == "4") { MessageBox.Show("Right answer"); } else if (textBox1.Text != "4") { MessageBox.Show("Nope, wrong answer"); } else if (textBox1.Text == "10") { MessageBox.Show("In base 4, yes, else, nope, wrong"); } [/code] If its 4, it says it's good, then if it's not 4, it'll say you are wrong. It never goes into the third statement. [code] if (textBox1.Text == "4") { MessageBox.Show("Right answer"); } else if (textBox1.Text == "10") { MessageBox.Show("In base 4, yes, else, nope, wrong"); } else { MessageBox.Show("Nope, wrong answer"); } [/code] Works better. (Added brackets but it does not really matter, it's just how I work) [editline]12th April 2013[/editline] Haha I can't seem to post the solution faster than you post new problems :v:[/QUOTE] Oh great! Now it works as expected, thanks man.
Also I recommend you to give your projects suitable names (So you can find them easier), as well as names for your controls. Ofcourse it won't really matter if there is just 1 label, 1 button, and 1 textbox, but if your solution has more controls than that it'll get extremely hard to keep track of what is what. Even more so if you would open it after not looking at it for a month.
I'm not going to make a whole new thread for this, but is there anyone here that would be willing to mess around with unity with me, if they have spare time? I'm no programmer myself, I'm more into 3D modeling, "texture art" and level design. Although learning to program for unity would be fun to learn since I have some programming knowledge; just not that much.
Sorry, you need to Log In to post a reply to this thread.