• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=dmillerw;43746451]Messing around with Mozilla's Rust for the first time, and I'm mostly getting the hang of it. Getting one error that I simply don't understand though. [IMG]http://puu.sh/6FPJ5.png[/IMG] [CODE]fn main() { for num in range(1, 101) { let result = if num % 3 == 0 { "Fizz" } else if num % 5 == 0 { "Buzz" }; println(result); } }[/CODE][/QUOTE] You have to end the "if else" clause with an else at the bottom. Example: [code]fn main() { for num in range(1, 101) { let result = if num % 3 == 0 { "Fizz" } else if num % 5 == 0 { "Buzz" } else {""}; println(result); } }[/code] If you don't then the compiler will complain that it got someting of the nothing type (aka. () ) when the num did not fit in the two above statements.
I been learning on code academy for javascript how fucked up and ineffecient is this retarded rock paper scizzors thing [code]//output is whatever they type var answerGen = function(playerNumber) { var answer = prompt("Player " + playerNumber + ", your turn! No peeking! Enter 'rock' , 'paper' , or 'scizzors'."); if (answer === ("rock")) {return(answer)} else if (answer === ("paper")) {return(answer)} else if (answer === ("scizzors")) {return(answer)} else {confirm("Invalid input. Please type 'rock', 'paper', or 'scizzors' exactly."); answerGen(playerNumber)} }; //just reruns the program if they click yes var playAgain = function(confirmation) { if ( confirmation === true ) {calcs(answerGen("one"),answerGen("two"))} else {console.log("See you next time!")} }; //all the calculations var calcs = function(reply1,reply2) { if (reply1 === "rock" && reply2 === "paper") {console.log("Player 2 wins!"); playAgain(confirm("Player 2 has won! Play again?"))} else if (reply1 === "rock" && reply2 === "scizzors") {console.log("Player 1 wins!"); playAgain(confirm("Player 1 has won! Play again?"))} else if (reply1 === "paper" && reply2 === "rock") {console.log("Player 1 wins!"); playAgain(confirm("Player 1 has won! Play again?"))} else if (reply1 === "paper" && reply2 === "scizzors") {console.log("Player 2 wins!"); playAgain(confirm("Player 2 has won! Play again?"))} else if (reply1 === "scizzors" && reply2 === "rock") {console.log("Player 2 wins!"); playAgain(confirm("Player 2 has won! Play again?"))} else if (reply1 === "scizzors" && reply2 === "paper") {console.log("Player 1 wins!"); playAgain(confirm("Player 1 has won! Play again?"))} else {console.log("It's a tie!"); playAgain(confirm("Nobody won! Play again?"))} }; //this initiates the program calcs(answerGen("one"),answerGen("two")); [/code]
I am trying to embed Lua into a game and have run into some design issues. I want to represent most things with Lua, for example effects on the player, weapons, ammo, pickups, and the like. However, I don't know how to represent them in code. I don't know what kind of hooks and calls I should add. On top of this I don't know if I should just expose the underlying Luabind object or to have functions that call upon this object. What I initially thought was to just have lua scripts that return a table containing information about whatever it is I need. However, I have run into problems trying to access this information. For example, how should an ammo pickup be represented? It should have an underlying ammo type and a response to when a player collides with it. How about projectiles? They should have an effect, which could be stored in ammo information, and a way to respond to collisions with the environment as well as the player. They should also be updated every tick to move. So how would one group data in a way that makes sense?
[QUOTE=Cesar Augusto;43754377]Someone know a good multi-platform C/C++ library for GUI building. Any different from Qt, GTK+ or even windows api.[/QUOTE] WxWidgets. But what's wrong with Qt?
[QUOTE=Cesar Augusto;43754377]Someone know a good multi-platform C/C++ library for GUI building. Any different from Qt, GTK+ or even windows api.[/QUOTE] Why bother? You will not find anything more convenient than Qt or GTK+. And besides, Qt and GTK+ are licensed with LGPL; it allows for use in proprietary products.
Using C# and Visual Studio Please forgive me but I am still new to this. I have a switch statement that holds a bunch of scenes for a story. I also have four labels with different options (labelOption1, labelOption2 etc). If you pick one option you get a new scene. If you pick another option you get another different scene. Now the problem is, in scene zero labelOption1 is there. If you click on the label it will load scene one. In scene one labelOption1 is there again, with different text, and when I click it I need it to go to scene two instead of scene one. The problem I am having is that scene one just gets completely skipped and goes straight to scene two. I could have multiple labels like labelOption1a, labelOption1b and so on. Have one visible and the others not. But I am sure there is a way for me to use the same label, change the text on the label, and go to the right scene. Some example code: [CODE] public int scene; public void NewScene() { // I am not doing scene++ here because the story is not linear. // Decisions you make can jump around through scenes. switch (scene) { //Wake up in bed case 1: pictureBoxMain.Image = Migraine_Simulator_v1.Properties.Resources.imageInBedHoldingHead; labelContext.Visible = true; labelContext.Text = "Good morning! Oh no, a migraine already?"; labelOption1.Text = "Take medication?"; labelOption2.Text = "Blow your brains out?"; break; //Take medication on desk at home. case 2: pictureBoxMain.Image = Migraine_Simulator_v1.Properties.Resources.imageDeskMedications; labelContext.Text = "Which medication are you going to take?"; labelOption1.Text = "Take Excedrin Migraine?"; labelOption2.Text = "Take Sumatriptan?"; labelOption3.Visible = true; labelOption3.Text = "Take both?"; labelOption4.Visible = true; labelOption4.Text = "Blow your brains out?"; break; } } private void labelOption1_Click(object sender, EventArgs e) { if (scene == 0) { scene = 1; NewScene(); } if (scene == 1) { scene = 2; NewScene(); } }[/CODE] It is obvious to me why when I click on the label it is skipping straight to scene 2. I am pretty sure I am missing something simple to achieve this. Maybe I just can't use switch for this. I just learned it that is why I am trying to use it on my own project.
@Jitterz You could do something like this [code] void DoScenes(int StartScene, int EndScene) { switch (StartScene) { case 1: { Console.WriteLine("DO SCENE 1"); if (EndScene == 1) break; goto case 2; } case 2: { Console.WriteLine("DO SCENE 2"); if (EndScene == 2) break; goto case 3; } case 3: { Console.WriteLine("DO SCENE 3"); if (EndScene == 3) break; break; } } } [/code] [editline]3rd February 2014[/editline] Every case will "fall trough" into another case, it will start at case StartScene and it will break if the current case is the end scene. The brackets around the case allow you to define variables with same name in different cases, i find it more readable but it is not necessary. However what you want to do can be done in different ways. [code] case N: { break; } [/code]
[QUOTE=cartman300;43764558] Helpful stuff thank you[/QUOTE] I do not think I am understanding the EndScene or how to get the scenes in between. When I click on the label I would call DoScenes(1, 3) it just skips to scene 3. If I do DoScenes(1, 1) then I only get the first scene and have no way to go to the next one. Thanks again for your assistance.
[B][/B][QUOTE=Jitterz;43764326]Using C# and Visual Studio Please forgive me but I am still new to this. I have a switch statement that holds a bunch of scenes for a story. I also have four labels with different options (labelOption1, labelOption2 etc). If you pick one option you get a new scene. If you pick another option you get another different scene. Now the problem is, in scene zero labelOption1 is there. If you click on the label it will load scene one. In scene one labelOption1 is there again, with different text, and when I click it I need it to go to scene two instead of scene one. The problem I am having is that scene one just gets completely skipped and goes straight to scene two. I could have multiple labels like labelOption1a, labelOption1b and so on. Have one visible and the others not. But I am sure there is a way for me to use the same label, change the text on the label, and go to the right scene. Some example code: [CODE] public int scene; public void NewScene() { // I am not doing scene++ here because the story is not linear. // Decisions you make can jump around through scenes. switch (scene) { //Wake up in bed case 1: pictureBoxMain.Image = Migraine_Simulator_v1.Properties.Resources.imageInBedHoldingHead; labelContext.Visible = true; labelContext.Text = "Good morning! Oh no, a migraine already?"; labelOption1.Text = "Take medication?"; labelOption2.Text = "Blow your brains out?"; break; //Take medication on desk at home. case 2: pictureBoxMain.Image = Migraine_Simulator_v1.Properties.Resources.imageDeskMedications; labelContext.Text = "Which medication are you going to take?"; labelOption1.Text = "Take Excedrin Migraine?"; labelOption2.Text = "Take Sumatriptan?"; labelOption3.Visible = true; labelOption3.Text = "Take both?"; labelOption4.Visible = true; labelOption4.Text = "Blow your brains out?"; break; } } private void labelOption1_Click(object sender, EventArgs e) { if (scene == 0) { scene = 1; NewScene(); } if (scene == 1) { scene = 2; NewScene(); } }[/CODE] It is obvious to me why when I click on the label it is skipping straight to scene 2. I am pretty sure I am missing something simple to achieve this. Maybe I just can't use switch for this. I just learned it that is why I am trying to use it on my own project.[/QUOTE] If I'm not mistaken you can fix your issue by inserting an "else":[code]if (scene == 0) { scene = 1; NewScene(); } else if (scene == 1) // insert else here { scene = 2; NewScene(); }[/code]
[QUOTE=Dienes;43765263][B][/B] If I'm not mistaken you can fix your issue by inserting an "else":[code]if (scene == 0) { scene = 1; NewScene(); } else if (scene == 1) // insert else here { scene = 2; NewScene(); }[/code][/QUOTE] Hahaha I knew it was something simple. I will see how this works out later on. Thank you.
I seem to be having trouble breaking into GUI stuff. I'm learning C# with the goal of making Windows Phone apps in mind, but while I can make console stuff that works, I have no clue where to start with Windows Phone, and GUI programming in general. I tried making a simple app, which was rather... confusing. There was stuff I didn't understand at all, like async. What would be a good route for me to take? Should I perhaps try WPF desktop apps first? It seems to be kind of similar in nature, also using XAML and all.
I have a JScrollPane that's displaying a JTable, and the JTable has varying row heights based on how many lines are needed to fit the text in each cell, as defined by this custom DefaultTableCellRenderer [code]renderer = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent (JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { Component rendererComp = super.getTableCellRendererComponent(table, obj, isSelected, hasFocus, row, column); if(column == 5) { JTextArea text = new JTextArea(obj.toString()); text.setFont(rendererComp.getFont()); text.setLineWrap(true); text.setWrapStyleWord(true); text.setSize(new Dimension( moves.getColumnModel().getColumn(column).getWidth(), 9999999)); text.setSize(text.getSize().width, text.getPreferredSize().height); table.setRowHeight(row, text.getPreferredSize().height); return text; } else return rendererComp; } };[/code] The reason I included this is that the JScrollPane was working fine before I added this renderer, but this needs to be the cell renderer because otherwise some of the information in the JTable simply isn't displayed. And it works fine for creating the rows at the correct heights. However, the JTable's preferredSize is apparently calculating incorrectly (I'm sure it's not and I fucked something up but that's what it seems like), as now the JScrollPane doesn't scroll all the way to the bottom. And when I called getRowHeight on every row in the JTable after setting the cell renderer for each column, they all return 16, there very clearly being rows with different heights in the JTable. Here's what the table looks like at the moment: [img]http://i.imgur.com/qgI3VXy.png[/img] As you can see, there's a sliver of the next row that should be displayed, but can't be because the scrollbar doesn't actually scroll all the way down the table. I'd just like to know how to accurately display the whole JTable in the JScrollPane. If seeing any other parts of the code would help just let me know.
-snip- nevermind, stupid question.
I'm going to create a mod for M&B Warband, but I'm coming up a bit short on the math end. I honestly have no idea where to start. Basically, I'm trying to derive a formula for something. Units have various attributes, one of which is their salary. I'm trying to find a relationship between their salary and about 20 other variables in the same equation. How do I approach this? Basically, one one side we have a, and on the other side we have the variables b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u on the other side. Somehow, a must be equal to some expression containing these variables. The question is what is it, and what steps do I take to discover this? IE: I'm trying to prove that a is a function of b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u. What do? By the way, this isn't language specific. If some poor soul wants to take a crack at it, I've got one test sample. Let: a = 36, b = 28, c= 56, d = 7, e = 5, f = 4, g = 4, h = 170, i = 170, j = 170, k = 170, l = 170, m = 170, n = 7, o = 5, p = 7 q = 0, r = 6, s = 7, t = 2 and u = 0
Thanks for indicate me wxWidgets. I really like Qt and GTK+, but I want to try something else.
[QUOTE=Irkalla;43769579]I'm going to create a mod for M&B Warband, but I'm coming up a bit short on the math end. I honestly have no idea where to start. Basically, I'm trying to derive a formula for something. Units have various attributes, one of which is their salary. I'm trying to find a relationship between their salary and about 20 other variables in the same equation. How do I approach this? Basically, one one side we have a, and on the other side we have the variables b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u on the other side. Somehow, a must be equal to some expression containing these variables. The question is what is it, and what steps do I take to discover this? IE: I'm trying to prove that a is a function of b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u. What do? By the way, this isn't language specific. If some poor soul wants to take a crack at it, I've got one test sample. Let: a = 36, b = 28, c= 56, d = 7, e = 5, f = 4, g = 4, h = 170, i = 170, j = 170, k = 170, l = 170, m = 170, n = 7, o = 5, p = 7 q = 0, r = 6, s = 7, t = 2 and u = 0[/QUOTE] Disassemble the program and extract the equation out of the code.
[QUOTE=Irkalla;43769579]Somehow, a must be equal to some expression containing these variables. The question is what is it, and what steps do I take to discover this?[/QUOTE] Unless the equation is really, really simple (i.e. linear) this is really difficult. In the linear case, you could use a set of linearly independent inputs and outputs to create a system of equations and solve it for the coefficients. You would either get no solutions (if the function is not linear), a set of solutions (if you did not give enough input to determine the function), or exactly one solution (if you're really lucky!). If it's a nonlinear function, you're probably better off reverse engineering it.
[post removed for further investigation]
[QUOTE=Larikang;43773175]Unless the equation is really, really simple (i.e. linear) this is really difficult. In the linear case, you could use a set of linearly independent inputs and outputs to create a system of equations and solve it for the coefficients. You would either get no solutions (if the function is not linear), a set of solutions (if you did not give enough input to determine the function), or exactly one solution (if you're really lucky!). If it's a nonlinear function, you're probably better off reverse engineering it.[/QUOTE] Functions up to the second power are also still directly solvable, just not with unique solution. All this would only work properly with exact maths and not discrete one where you truncate or round though, so disassembling is likely easier.
I've asked about this a few times, but I never seem to get much of an answer. If I am working on a game, and I have my main Game class, an EntityManager class, and a Renderer class, What do I do with them? I am always confused when it comes to finding a good way to deal with these things. Should they just be static variables in the Game class? Should the entire class just be static? Should these classes even be accessible at all by other things? Usually I just create them when the game starts and store them in a static variable, so that anywhere in the game I can call Game.input.getMouse or Game.renderer.setClearColor but I feel like this is "dirty". How should I be storing and managing game "systems"?
Can anyone see anything wrong with this? [cpp] unsigned char image[256 * 256 * 4]; for(int y = 0; y < 256; y++) { for(int x = 0; x < 256; x++) { unsigned char val = (unsigned char)(noise.Generate(x, y) * 100); image[0 + x * 4 + y * 256] = 255; image[1 + x * 4 + y * 256] = val; image[2 + x * 4 + y * 256] = val; image[3 + x * 4 + y * 256] = 255; } } t->LoadData(image,256,256); //..... //Convert the data to a texture glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, image ); [/cpp] It should be giving me a opaque image that is either red or any combination of the other colors. but instead I get: [IMG]http://i.imgur.com/iQwbIHS.png[/IMG] Where only the red (and the small static in the rest of it) is opaque, the rest is transparent.
[QUOTE=Duskling;43773700]I've asked about this a few times, but I never seem to get much of an answer. If I am working on a game, and I have my main Game class, an EntityManager class, and a Renderer class, What do I do with them? I am always confused when it comes to finding a good way to deal with these things. Should they just be static variables in the Game class? Should the entire class just be static? Should these classes even be accessible at all by other things? Usually I just create them when the game starts and store them in a static variable, so that anywhere in the game I can call Game.input.getMouse or Game.renderer.setClearColor but I feel like this is "dirty". How should I be storing and managing game "systems"?[/QUOTE] Whatever works for you. There are no rules and in this case barely any difference, and what the best implementation is is highly situational.
[QUOTE=laharlsblade;43768367]I have a JScrollPane that's displaying a JTable, and the JTable has varying row heights based on how many lines are needed to fit the text in each cell, as defined by this custom DefaultTableCellRenderer The reason I included this is that the JScrollPane was working fine before I added this renderer, but this needs to be the cell renderer because otherwise some of the information in the JTable simply isn't displayed. And it works fine for creating the rows at the correct heights. However, the JTable's preferredSize is apparently calculating incorrectly (I'm sure it's not and I fucked something up but that's what it seems like), as now the JScrollPane doesn't scroll all the way to the bottom. And when I called getRowHeight on every row in the JTable after setting the cell renderer for each column, they all return 16, there very clearly being rows with different heights in the JTable. Here's what the table looks like at the moment: [img]http://i.imgur.com/qgI3VXy.png[/img] As you can see, there's a sliver of the next row that should be displayed, but can't be because the scrollbar doesn't actually scroll all the way down the table. I'd just like to know how to accurately display the whole JTable in the JScrollPane. If seeing any other parts of the code would help just let me know.[/QUOTE] Have you tried setting table.setFillsViewportHeight as true?
[QUOTE=Irkalla;43769579]I'm going to create a mod for M&B Warband, but I'm coming up a bit short on the math end. I honestly have no idea where to start. Basically, I'm trying to derive a formula for something. Units have various attributes, one of which is their salary. I'm trying to find a relationship between their salary and about 20 other variables in the same equation. How do I approach this? Basically, one one side we have a, and on the other side we have the variables b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u on the other side. Somehow, a must be equal to some expression containing these variables. The question is what is it, and what steps do I take to discover this? IE: I'm trying to prove that a is a function of b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, and u. What do? By the way, this isn't language specific. If some poor soul wants to take a crack at it, I've got one test sample. Let: a = 36, b = 28, c= 56, d = 7, e = 5, f = 4, g = 4, h = 170, i = 170, j = 170, k = 170, l = 170, m = 170, n = 7, o = 5, p = 7 q = 0, r = 6, s = 7, t = 2 and u = 0[/QUOTE] No matter how you go about this, you'll need more than 1 test sample. What you'll want to do is hold all variables constant except 1 (such as 'b') and then vary b. Note how 'a' changes as b varies. Collect enough points so you can fit a regression line (exponential, polynomial, linear -- whatever works). Then take the derivative. That's your partial derivative of a=f(...) with respect to b, i.e.: a'/b=f'(...)/b. Do that for all the variables. I'll wait. ... Right, moving along? You now have 20 or so partial derivatives of this function. Now the fun part. Find a function a=F(...) such that F'(...)/z = f'(...)/z for any of your variables as listed above. The trick here is just to use your original regression lines and throw in a constant. We can combine all the constants. So we'll be looking at this: a = R_ab(b) + R_ac(c) + ... + R_au(c) + C = F(...) where R_ab(b) is the regression line fit to the change of 'a' as 'b' varies and all other variables are held constant. C is a constant. To find C, take the equation above and set everything to 0. Then do the same for the 'actual' formula -- the blackbox. Suppose that your equation says that F(0,0,...,0) = 1 when the game says that it should be 23. 23-1 = 22, so C = 22.
[QUOTE=ThePuska;43772193]Disassemble the program and extract the equation out of the code.[/QUOTE] They're human defined. But surely, the human brain is a computer. If a computer can assign some relationship to these, the relationship must be provable. [editline]3rd February 2014[/editline] [QUOTE=Dvd;43778869]No matter how you go about this, you'll need more than 1 test sample. What you'll want to do is hold all variables constant except 1 (such as 'b') and then vary b. Note how 'a' changes as b varies. Collect enough points so you can fit a regression line (exponential, polynomial, linear -- whatever works). Then take the derivative. That's your partial derivative of a=f(...) with respect to b, i.e.: a'/b=f'(...)/b. Do that for all the variables. I'll wait. ... Right, moving along? You now have 20 or so partial derivatives of this function. Now the fun part. Find a function a=F(...) such that F'(...)/z = f'(...)/z for any of your variables as listed above. The trick here is just to use your original regression lines and throw in a constant. We can combine all the constants. So we'll be looking at this: a = R_ab(b) + R_ac(c) + ... + R_au(c) + C = F(...) where R_ab(b) is the regression line fit to the change of 'a' as 'b' varies and all other variables are held constant. C is a constant. To find C, take the equation above and set everything to 0. Then do the same for the 'actual' formula -- the blackbox. Suppose that your equation says that F(0,0,...,0) = 1 when the game says that it should be 23. 23-1 = 22, so C = 22.[/QUOTE] Alright, I'll gather a bunch of samples. I have also discovered more variables in the relationship -- 9 more. The cool thing is, I don't really need something exact, just something reasonably approximate. I'm not exactly following you 100% or even 50% for that matter. If it would please you, could we discuss this at a later time in a different setting? Also, I've run out of latin letters to name the variables. What do?
[QUOTE=Irkalla;43780159]They're human defined. But surely, the human brain is a computer. If a computer can assign some relationship to these, the relationship must be provable.[/quote] I'm not sure I follow. [QUOTE=Irkalla;43780159]I have also discovered more variables in the relationship -- 9 more. [/QUOTE] I am now positive that I don't follow. Could you please explain *exactly* what you're doing?
[QUOTE=MrTilepy;43776254]Have you tried setting table.setFillsViewportHeight as true?[/QUOTE] Nope, I actually got a solution (kinda) on StackOverflow though, thanks anyway. I specifically set preferredSize on the JTable, and commenting out that line made it work. What confuses me though is that the preferred size I set is exactly the same as the actual preferredSize it has now that I don't set it at all, so I don't understand exactly why this worked. I'll keep your idea in mind though because it sounds like it might work if this happens again.
Java/Android question: Can HashMap contain several key-value sets and how do I access and set each of them? Is it like a 2-dimensional array? I have a SQLite database where I store information and I want to access my rows in my activity. Currently I can access a single row of information by storing it in a List, but how exactly does HashMap work? I tried storing each row like this: [CODE] HashMap<String,String[]> [/CODE] but Eclipse didn't like that. Some code to help explain [CODE]public List<String> getFormList() { List<String> list = new ArrayList<String>(); SQLiteDatabase db = this.getReadableDatabase(); String formQuery = "SELECT * FROM " + TABLE_FORM; Cursor cursor = db.rawQuery(formQuery, null); cursor.moveToFirst(); if (cursor.getCount() > 0) { do { list.add(cursor.getString(cursor.getColumnIndex(KEY_FORMNAME))); } while (cursor.moveToNext()); } cursor.close(); db.close(); return list; }[/CODE] This stores each formname in a List that I can very easily place in my ListView, but how do I use the HashMap? [CODE]public HashMap<String,String> getForm(String formname) { HashMap<String,String> form = new HashMap<String,String>(); SQLiteDatabase db = this.getReadableDatabase(); String formQuery = "SELECT * FROM " + TABLE_FORM + " WHERE formname = " + formname; Cursor cursor = db.rawQuery(formQuery, null); cursor.moveToFirst(); if(cursor.getCount() > 0) { do { form.put(KEY_ID, cursor.getString(cursor.getColumnIndex(KEY_ID))); form.put(KEY_USERNAME, cursor.getString(cursor.getColumnIndex(KEY_USERNAME))); form.put(KEY_FORMID, cursor.getString(cursor.getColumnIndex(KEY_FORMID))); form.put(KEY_FORMNAME, cursor.getString(cursor.getColumnIndex(KEY_FORMNAME))); form.put(KEY_QID, cursor.getString(cursor.getColumnIndex(KEY_QID))); form.put(KEY_QUESTION, cursor.getString(cursor.getColumnIndex(KEY_QUESTION))); form.put(KEY_CREATED_AT, cursor.getString(cursor.getColumnIndex(KEY_CREATED_AT))); } while (cursor.moveToNext()); } cursor.close(); db.close(); return form; }[/CODE] What does the HashMap returned in the 2nd snippet contain?
The hash map contains the 7 keys (e.g.: KEY_ID) and the values of the last item the cursor iterated across. What you probably want to do is use cursor.getColumnIndex(KEY_ID) as the key for each cursor item and then store an array as the value for that key -- representing the other fields for the item.
I fucked up and made it complicated when it didn't need to be. Instead of creating a table which would have included 30 rows for 30 questions, I can just store the questions in 1 long string and then split it when I need to, which means that a form with 30 questions still will be only 1 row. The solution I used at first was the Multimap from Guava which can store several values to a single key, which would have worked for my problem but the table would still be incredibly poorly designed. Anyways, thanks for the quick reply
Sorry, you need to Log In to post a reply to this thread.