• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=FPSMango;27085575]About do you mean ref[1]; As far as I've learnt, an array is just a address that is put in front of the actual variables it contains(That sounded weird on paper but I think I get it in my head) so adding 1(adding 8 bitwise to the address since an int is 8 bytes long?) to the address of the array will be the equivalent of arr[0] and if I then add 1 to the address of arr[0] i get arr[1] and so forth. And no it didn't work unfortunetly. The problem isn't what goes on there. The problem is that the compiler doesn't like that i pass the address of a int[2] to a pointer of type int. But I don't know enough c++ to know how to make a pointer to fit unfortunetly.[/QUOTE] Change++ goes out of bounds, because you are already starting at ref[1] and arrays are counted from 0, so you are going to ref[2] which doesn't exist. [editline]30th December 2010[/editline] Also what are height and length? Pointers? Integers?
Anyone know a good tutorial on how to make a tile based level editor?
Here's the whole class: [code]class cube { public: void setPos(int x, int y) { PosX = x; PosY = y; } void setSize(int flength,int fheight){ length = flength; height = fheight; } void getSizeREF(int* ref){ int* change; change = ref; *change = length; change++; *change = height; } private: int PosX, PosY, length, height; };[/code] Your proposal doesn't solve the problem since, due to the error I've got problems with, the code never get to the part where it would go out of bounds as you said, it would be a problem later though. Still, I wish someone would be able to solve the error I proposed earlier. I know it's so many more easier ways to solve this like making the variables public, however I'm doing this to learn so fixing it the easy way wouldn't teach me much.
You need to pass it the value not a reference so: myfunc(array); and have the function take a reference not a pointer so: void myfunc(int& array)//not sure if that int should be an array or not tho [editline]31st December 2010[/editline] [QUOTE=Dj-J3;27086600]Anyone know a good tutorial on how to make a tile based level editor?[/QUOTE] heres a tutorial, dont know how good it is tho [url]http://www.youtube.com/watch?v=Tbs5EA-9Zfg[/url]
[QUOTE=FPSMango;27084933]I'm not very good at c++ and these fucking pointers are hard to get a grip on, I pass the reference of a int[2] onto a function that takes the reference and changes [1] and [2] but when I run it, it tells me that I "cannot convert parameter 1 from 'int (*)[2]' to 'int *" I don't understand why this is a problem since the pointer only holds the reference to the variable(I think, but I bet this is wrong) Here's the code: -snip- Help a dabbling programmer Facepunch! What was the c++ bbcode again?[/QUOTE] When you declare an array its identifier acts as a pointer to the first element. Also, even if the function accepted it as a pointer you can still use regular array syntax to get the elements! So, [code] void getSizeREF(int *ref){ [b] ref[0] = length; ref[1] = height;[/b] } //Later in the code: int arr[2]; [b]testCube.getSizeREF(arr);[/b] std::cout << arr[[b]0[/b]]; std::cout << arr[[b]1[/b]]; [/code] Should work. If you want to keep the original layout of getSizeREF, just remove the +1 from [i]change = ref+1;[/i] [editline]31st December 2010[/editline] Is there any way to have the OpenGL framebuffer be larger than the window it's associated with? I've implemented some instant resolution change code and, while it works, the newly-covered area is pure white until the next frame draws. The code's not complicated, either: [code] glViewport(0,0,width,height); SetWindowPos(hWnd,HWND_TOPMOST,xPos,yPos,width,height,NULL);[/code] But inserting draw calls between the viewport change and window pos/size change doesn't prepare it for the new size.
[QUOTE=Richy19;27087043]heres a tutorial, dont know how good it is tho [url]http://www.youtube.com/watch?v=Tbs5EA-9Zfg[/url][/QUOTE] Ah, thanks. He shared the project, so i can atleast see how he coded it, incase the tutorial isn't very good. :v:
Well, I've hit a bit of a snag. How do I get a program to detect information off of a webpage? I'm making a search engine for bans to help out admins.
What's the easiest way to make a 2D camera in XNA?
What's a good JSON library for .Net ?
[quote=pixen;27112461]what's a good json library for .net ?[/quote] [url=http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx].net[/url]
[QUOTE=Combino;27112963][url=http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx].net[/url][/QUOTE] Any way of making it work for a non-ASP.Net app ? I can't even find System.Web.Extensions
[QUOTE=PiXeN;27113098]Any way of making it work for a non-ASP.Net app ? I can't even find System.Web.Extensions[/QUOTE] Set your target framework to be .NET Framework 4, not .NET Framework 4 Client Profile
I'm having trouble implementing Lua in c++. This is currently my code. [cpp] #include "stdafx.h" #include <iostream> extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" } int _tmain(int argc, _TCHAR* argv[]) { lua_State *L = lua_open(); luaopen_base(L); //this is the function that lua seems to crash on. luaopen_io(L); //Another one it crashes on. luaopen_table(L); //Crashes here too. luaopen_string(L); //Loads just fine. luaopen_math(L); //loads fine. // make my_function() available to Lua programs lua_register(L, "my_function", my_function); int s = luaL_loadfile(L, "test.lua"); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); //This functions returns any lua errors lua_close(L); int x = 0; //I know, this is a shitty way to pause. std::cin >> x; return 0; } [/cpp] As soon as the code hits the part where it loads base through table it shuts down and returns 1. Am I implementing it wrong?
[QUOTE=Anthophobian;27128127]I'm having trouble implementing Lua in c++. This is currently my code. [cpp] #include "stdafx.h" #include <iostream> extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" } int _tmain(int argc, _TCHAR* argv[]) { lua_State *L = lua_open(); luaopen_base(L); luaopen_io(L); luaopen_table(L); //this is the function that lua seems to crash on. luaopen_string(L); luaopen_math(L); // make my_function() available to Lua programs lua_register(L, "my_function", my_function); int s = luaL_loadfile(L, "test.lua"); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); //This functions returns any lua errors lua_close(L); int x = 0; //I know, this is a shitty way to pause. std::cin >> x; return 0; } [/cpp] As soon as the code hits the part luaopen_table(L); it shuts down and returns 1. Am I implementing it wrong?[/QUOTE] Try replacing the luaopen_* calls with luaL_openlibs(L).
Have my babies MakeR. :love:
[QUOTE=Anthophobian;27128301]Have my babies MakeR. :love:[/QUOTE] ok
Is there any way to decompress a gzip string with boost? It works with files but not just a plain gzip'd string.
Having a little trouble with contructors in C++. Here is my code - Point.h [code] #include "vmath.h" using namespace vmath; class Point { public: float x; float y; float z; Point(float x1, float y1, float z1); Point(); }; [/code] Point.cpp [code] #include "vmath.h" #include "Point.h" using namespace vmath; Point::Point(float x1, float y1, float z1) { x = x1; y = y1; z = z1; } [/code] Sphere.h [code] #include "vmath.h" #include "Point.h" using namespace vmath; class Sphere { public: Point Position; float Radius; Sphere::Sphere(Point p, float r); Sphere::Sphere(); }; [/code] Sphere.cpp [code] #include "vmath.h" #include "Point.h"; #include "Sphere.h" using namespace vmath; Sphere::Sphere(Point p, float r) { Position = p; Radius = r; } Sphere::Sphere() { } [/code] main.cpp [code] Point p = Point(0.00f, 0.00f, 0.00f); Sphere s = Sphere(p, 0.00f); [/code] Here is the error I get - [code] Error: no instance of constructor Sphere::Sphere matches the argument list [/code]
[QUOTE=AaRoNg11;27135390]words[/QUOTE] It should just be Point p(0.f, 0.f, 0.f) and Sphere s(p, 0.f);
[QUOTE=WTF Nuke;27135435]It should just be Point p(0.f, 0.f, 0.f) and Sphere s(p, 0.f);[/QUOTE] I tried that and received the same error :/
[QUOTE=AaRoNg11;27135506]I tried that and received the same error :/[/QUOTE] I spot one error, you have to declare the constructors like this Point(float, float, float) not Point(float x1, float y1, float z1);
[QUOTE=AaRoNg11;27135390]Having a little trouble with contructors in C++. Here is my code - Point.h [code] #include "vmath.h" using namespace vmath; class Point { public: float x; float y; float z; Point(float x1, float y1, float z1); Point(); }; [/code] Point.cpp [code] #include "vmath.h" #include "Point.h" using namespace vmath; Point::Point(float x1, float y1, float z1) { x = x1; y = y1; z = z1; } [/code] Sphere.h [code] #include "vmath.h" #include "Point.h" using namespace vmath; class Sphere { public: Point Position; float Radius; Sphere::Sphere(Point p, float r); Sphere::Sphere(); }; [/code] Sphere.cpp [code] #include "vmath.h" #include "Point.h"; #include "Sphere.h" using namespace vmath; Sphere::Sphere(Point p, float r) { Position = p; Radius = r; } Sphere::Sphere() { } [/code] main.cpp [code] Point p = Point(0.00f, 0.00f, 0.00f); Sphere s = Sphere(p, 0.00f); [/code] Here is the error I get - [code] Error: no instance of constructor Sphere::Sphere matches the argument list [/code][/QUOTE] You have Sphere::Sphere in your class declaration, change it to Sphere and add header guards.
[QUOTE=AaRoNg11;27135390] [code] #include "vmath.h" #include "Point.h" using namespace vmath; class Sphere { public: Point Position; float Radius; Sphere::Sphere(Point p, float r); Sphere::Sphere(); }; [/code] Just make it Sphere(Point p, float r), not Sphere::Sphere. (In the definition file, however definitely make it Sphere::Sphere :P) EDIT: :ninja: Damnit efex :argh:
[QUOTE=WTF Nuke;27135579]I spot one error, you have to declare the constructors like this Point(float, float, float) not Point(float x1, float y1, float z1);[/QUOTE] Please learn C++ before helping someone out.
Fixed. Added #pragma once to each header file and now everything works! Thank you efeX :)
[QUOTE=Overv;27135762]Please learn C++ before helping someone out.[/QUOTE] Woops I am an idiot sorry.
efex, I like your avatar.
[QUOTE=efeX;27135090]Is there any way to decompress a gzip string with boost? It works with files but not just a plain gzip'd string.[/QUOTE] [cpp]boost::iostreams::filtering_streambuf<boost::iostreams::input> gzipStreamBuf(std::ostringstream(gzipString)); gzipStreamBuf.push(boost::iostreams::gzip_decompressor()); std::ostream gunzippedStream(gzipStreamBuf);[/cpp] Summin' like that.
2 questions a) if i want to make a windowed program but i dont want it to be open source at first what library should i use? i cant use QT (unless i pay) so i think that leaves GTK or WX b) how would i integrate sfml into part of the window? so i can have openGL rendering in the window
Qt is LGPL, so unless you make changes to the Qt library you're fine with developing code using any other license. Qt and wxWidgets both have a GL widget and for GTK+ there's GtkGLExt, so there's no need for SFML.
Sorry, you need to Log In to post a reply to this thread.