Why when I type and convert a variable toString(var) do I get a nil value error?
[code]
num = 5
toString(num)
print(num)
[/code]
[QUOTE=JakeAM;37633308]Why when I type and convert a variable toString(var) do I get a nil value error?
[code]
num = 5
toString(num)
print(num)
[/code][/QUOTE]
Assuming this is Lua, tostring returns the value as a string.
[code]num = 5
str = tostring(num)
print(str)[/code]
It is Lua yes, so it changes the variable name to str?
[QUOTE=JakeAM;37633478]It is Lua yes, so it changes the variable name to str?[/QUOTE]
The num variable does not change and still holds the number 5. The str value is set to the return value of tostring, which is a string representation of num.
[editline]11th September 2012[/editline]
You can still use the variable num to access the number 5 after calling tostring. tostring does not modify the variable passed to it.
So I did...
[code]num = 5
stringvar = toString(num)
print(stringvar)[/code]
Why doesn't that work?
[QUOTE=JakeAM;37633811]So I did...
[code]num = 5
stringvar = toString(num)
print(stringvar)[/code]
Why doesn't that work?[/QUOTE]
Try lowercase S on toString.
Thanks, can't believe I forgot that.
How would I compare a variable to a value inside a table? I was thinking...
[code]
function chests:receive()
while true do
local event, id, det = os.pullEvent
if event == "rednet_message" then
for k,v in pairs(self) do
if type(v) == "table" and
self[k][detector] == det then
self[k][amount] = self[k][amount] + 1
end
end
end
end
end
[/code]
[editline]12th September 2012[/editline]
And how could I take a variable and split it into two if it was a string and a number like "cheese 30" but the text and number are different every time, would I use string.find?
[QUOTE=JakeAM;37634200]Thanks, can't believe I forgot that.
How would I compare a variable to a value inside a table? I was thinking...
[code]
function chests:receive()
while true do
local event, id, det = os.pullEvent
if event == "rednet_message" then
for k,v in pairs(self) do
if type(v) == "table" and
self[k][detector] == det then
self[k][amount] = self[k][amount] + 1
end
end
end
end
end
[/code][/QUOTE]
Your code is almost right, although I'm not sure why you have the infinite while loop that you never break out from. You use self[k] in your for-in loop where you should be using the variable v, also you are missing the if keyword. self[k][amount] should be v.amount or v["amount"].
[QUOTE=JakeAM;37634200]And how could I take a variable and split it into two if it was a string and a number like "cheese 30" but the text and number are different every time, would I use string.find?[/QUOTE]
If you want to just split a string at the first space you can use string.match:
[lua]local var = "cheese 30"
local s, n in string.match(var, "(.-)%s(.+)")
-- s = "cheese"
-- n = "30"
[/lua]
If you want to match exactly a alphanumeric string and a well formed number you need to do more complex pattern matching, something like this may work:
[lua]local var = "cheese 5.4e-8"
local s, n = string.match(var, "(%w-)%s(%-?%d*%.?%d+[eE]?[%-%+]?%d-)$")
-- s = "cheese"
-- n = "5.4e-8"[/lua]
Simple question.
how do I build a project in Code::Blocks and SFML, with the dll's included in the exe?
[QUOTE=Mete;37644567]Simple question.
how do I build a project in Code::Blocks and SFML, with the dll's included in the exe?[/QUOTE]
Impossible, DLLs are a "Dynamic Linked Library". Dynamic libraries (also known as shared libraries) are linked on run-time or load-time. They have the ".dll" extension on Windows, and ".so" extension on Unix-like systems (such as Linux and OS X).
To link at compile-time (putting the library into the executable), you need to link to the static library. The extension for these varies, but Windows usually uses ".lib" and Unix-likes usually use ".a" (they are effectively equivalent, assuming they are compiled for the same platform). Most libraries have this included along with the DLL. Adding it to your project with Code::Blocks is fairly simple (see below).
If you do not have a static library, build it yourself. The specific libraries usually have instructions for this. Also, some require a special #define to use the static library. GLEW, for example, requires you to #define GLEW_STATIC before including it anywhere. Just drop the built library wherever the rest of your libraries live (or your project folder itself).
Note: To add it to CB, it's under "Project", "Build options...", "Linker settings". Choose the specific build target for each if you want to have a specific library for different ones (for example, some libraries come with debug binaries).
After months of trying, I've finally nailed down why some of the effects and the units in this game aren't lined up.
[IMG]http://img440.imageshack.us/img440/750/examplekp.jpg[/IMG]
See that little white box in the corner? That's the boundaries of the smoke special effect. That yellow line that goes to the corner of it? It's supposed to line up with the center, instead it goes toward the upper left corner of the box. Now the problem is I don't know how to use matrix multiplication for the life of me, so when I mix up the matrix transforms they tend to go all over the place, it's a miracle I got it working like it is.
[CODE]
AffineTransform temptransform = new AffineTransform();
if (currentimage < (double)numofimages)
//The next line moves it onto it's screen position considering it's x, y, and z coordinates
temptransform.translate((x - viewX) + (z * (x - viewX - gfxmanager.resolution_x/2)) / gfxmanager.resolution_x/2,
(y - viewY) + (z * (y - viewY - gfxmanager.resolution_y*0.625)) / gfxmanager.resolution_y*0.625); //Fancy pseudo 3D here
//temptransform.scale(scale, scale); //scales it
//temptransform.rotate(findDirection(),size/2,size/2); //rotates it
//temptransform.translate(0.0D - size / 2D, 0.0D - size / 2D); //Should move it to the center but doesn't.
[/CODE]
The code here rotates it around the upper left corner, but no matter what I do I can't get the center of the image to line up with the line pointing to it's virtual "position", in this case x and y. Changing it to add the or remove the commented lines or changing the order doesn't help.
Now if I change the big scary math function to :
[CODE]
temptransform.translate((x - viewX - size/2) +
//Fancy pseudo 3D here, irrelevant.
(z * (x - viewX - gfxmanager.resolution_x/2)) / gfxmanager.resolution_x/2,
(y - viewY - size/2) +
//Fancy pseudo 3D here too
(z * (y - viewY - gfxmanager.resolution_y*0.625)) / gfxmanager.resolution_y*0.625);
[/CODE]
[img]http://img38.imageshack.us/img38/742/smokevp.jpg[/img]
It still doesn't look right. And at this point I'm stumped because I can't seem to figure out how to change it for the life of me, but then again my program seems to violate the laws of simple math sometimes so I don't know.
Try translating it before you rotate it?
Scale Down
Translate left/up by 1/2 new width/height
Rotate from center.
I'm a very experience C++ programmer (read: copy-pasting from tutorials) and I just went to compile a really simple lesson and I got this error (in visual c++ 2010)
[CODE]1>------ Build started: Project: helloworld, Configuration: Debug Win32 ------
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: The build stopped unexpectedly because of an internal failure.
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: Microsoft.Build.Exceptions.BuildAbortedException: Build was canceled. MSBuild.exe could not be launched as a child node as it could not be found at the location "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe". If necessary, specify the correct location in the BuildParameters, or with the MSBUILD_EXE_PATH environment variable.
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: at Microsoft.Build.BackEnd.NodeManager.AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration)
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: at Microsoft.Build.BackEnd.NodeManager.CreateNode(NodeConfiguration configuration, NodeAffinity nodeAffinity)
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.PerformSchedulingActions(IEnumerable`1 responses)
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node, BuildRequestBlocker blocker)
1>C:\Users\Jacob\Downloads\cpluspus\helloworld\helloworld\helloworld.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.IssueRequestToScheduler(BuildSubmission submission, Boolean allowMainThreadBuild, BuildRequestBlocker blocker)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========[/CODE]
I don't think it's caused by my 'program' but here that is anyway
[CODE]#include "stdafx.h"
#include <iostream>
int dobl(int y)
{
return 2 * y;
}
int main()
{
using namespace std;
cout << "Enter a number to be doubled: "; // ask user for a number
int x;
cin >> x; // read number from console and store it in x
cout << "the double is " << dobl(x) << endl;
return 0;
}
[/CODE]
Alright, another LOVE related question here - I'm a little unsure how to structure my little game, coming from Java and such I would, for example, have a player class.
What do you guys recommend? A module for each kind of distinct object?
I wanted to try out NetBeans with MinGW, but I get a lot of "was not declared in this scope".
For instance all GL variables like GLuint, and M_PI. The header files for these are included.
[QUOTE=zakedodead;37648201]I'm a very experience C++ programmer (read: copy-pasting from tutorials) and I just went to compile a really simple lesson and I got this error (in visual c++ 2010)
I don't think it's caused by my 'program' but here that is anyway
[CODE]#include "stdafx.h"
#include <iostream>
int dobl(int y)
{
return 2 * y;
}
int main()
{
using namespace std;
cout << "Enter a number to be doubled: "; // ask user for a number
int x;
cin >> x; // read number from console and store it in x
cout << "the double is " << dobl(x) << endl;
return 0;
}
[/CODE][/QUOTE]
There's definitely a problem with your setup, because [url=http://codepad.org/ChXXZu7p]it compiles succesfully[/url]
Can't help much but it could be caused by not having MSbuild.exe in your PATH variable (search for it and try adding it's directory into PATH)
[QUOTE=Em See;37648226]Alright, another LOVE related question here - I'm a little unsure how to structure my little game, coming from Java and such I would, for example, have a player class.
What do you guys recommend? A module for each kind of distinct object?[/QUOTE]
It's easy. Depends on what exactly do you need: game loop is simple and is neatly described in [url=https://love2d.org/wiki/Tutorial:Callback_Functions]wiki[/url]
For classes, [url=https://love2d.org/wiki/Category:Libraries]you might probably want to use libraries[/url]
[QUOTE=vombatus;37649071]There's definitely a problem with your setup, because [url=http://codepad.org/ChXXZu7p]it compiles succesfully[/url]
Can't help much but it could be caused by not having MSbuild.exe in your PATH variable (search for it and try adding it's directory into PATH)
It's easy. Depends on what exactly do you need: game loop is simple and is neatly described in [url=https://love2d.org/wiki/Tutorial:Callback_Functions]wiki[/url]
For classes, [url=https://love2d.org/wiki/Category:Libraries]you might probably want to use libraries[/url][/QUOTE]
I exited/restarted the compiler and it worked.
Could someone suggest a 3D framework to me? All I really want is drawing and loading models but OGRE and the like add a bunch of unnecessary stuff.
OOGL
I'd prefer to not have to roll my own model importer but you're probably right, it's the closest I'm going to get.
OOGL has some basic model importers already
Oh. Well then.
Hi !
I'm currently learning opengl ( and I must use opengl 2.0 :suicide: ) at the university and I've got this homework.
I need to draw the [URL="http://en.wikipedia.org/wiki/Sierpinski_carpet"]Sierpinski Carpet[/URL], but I don't know where to start out.
I know how to draw a Sierpinski Gasket( the triangle ), but when I'm the trying the other one I get lost.
I'm using OOGL and I can't load a .obj model. I use the line:
[CODE]GL::Mesh object("cube.obj");[/CODE]
but I get the VS2010 debugger shouting about a vector being out of range. cube.obj was exported with the default Blender Wavefront (.obj) settings.
[QUOTE=evil-tedoz;37656641]Hi !
I'm currently learning opengl ( and I must use opengl 2.0 :suicide: ) at the university and I've got this homework.
I need to draw the [URL="http://en.wikipedia.org/wiki/Sierpinski_carpet"]Sierpinski Carpet[/URL], but I don't know where to start out.
I know how to draw a Sierpinski Gasket( the triangle ), but when I'm the trying the other one I get lost.[/QUOTE]
A dumb way is to use this:
[code]/**
* Decides if a point at a specific location is filled or not. This works by iteration first checking if
* the pixel is unfilled in successively larger squares or cannot be in the center of any larger square.
* @param x is the x coordinate of the point being checked with zero being the first pixel
* @param y is the y coordinate of the point being checked with zero being the first pixel
* @return 1 if it is to be filled or 0 if it is open
*/
int isSierpinskiCarpetPixelFilled(int x, int y)
{
while(x>0 || y>0) // when either of these reaches zero the pixel is determined to be on the edge
// at that square level and must be filled
{
if(x%3==1 && y%3==1) //checks if the pixel is in the center for the current square level
return 0;
x /= 3; //x and y are decremented to check the next larger square level
y /= 3;
}
return 1; // if all possible square levels are checked and the pixel is not determined
// to be open it must be filled
}[/code]
With glDrawPixles.
Else you can make some kind of recursive function that divides each square in 9 pieces and run the function for each square except the middle one.
[QUOTE=AlienCat;37660739]A dumb way is to use this:
[code]/**
* Decides if a point at a specific location is filled or not. This works by iteration first checking if
* the pixel is unfilled in successively larger squares or cannot be in the center of any larger square.
* @param x is the x coordinate of the point being checked with zero being the first pixel
* @param y is the y coordinate of the point being checked with zero being the first pixel
* @return 1 if it is to be filled or 0 if it is open
*/
int isSierpinskiCarpetPixelFilled(int x, int y)
{
while(x>0 || y>0) // when either of these reaches zero the pixel is determined to be on the edge
// at that square level and must be filled
{
if(x%3==1 && y%3==1) //checks if the pixel is in the center for the current square level
return 0;
x /= 3; //x and y are decremented to check the next larger square level
y /= 3;
}
return 1; // if all possible square levels are checked and the pixel is not determined
// to be open it must be filled
}[/code]
With glDrawPixles.
Else you can make some kind of recursive function that divides each square in 9 pieces and run the function for each square except the middle one.[/QUOTE]
A better way is to load the image from wikipedia and draw it as a sprite.
[QUOTE=MrBob1337;37656918]I'm using OOGL and I can't load a .obj model. I use the line:
[CODE]GL::Mesh object("cube.obj");[/CODE]
but I get the VS2010 debugger shouting about a vector being out of range. cube.obj was exported with the default Blender Wavefront (.obj) settings.[/QUOTE]
You need to export with normals, texture coordinates and vectors, it's currently optimized to be fast and not very tolerant. Sorry about that.
Actually, if you send me that file, I'll submit an update that parses it.
[QUOTE=vombatus;37649071]
It's easy. Depends on what exactly do you need: game loop is simple and is neatly described in [url=https://love2d.org/wiki/Tutorial:Callback_Functions]wiki[/url]
For classes, [url=https://love2d.org/wiki/Category:Libraries]you might probably want to use libraries[/url][/QUOTE]
I should clarify this - I understand enough to get a (very) simple game going on, but I work entirely in the single main.lua file. I know this isn't the way to do it and I'd like to know how to structure a game in LOVE. Say... an asteroids type game - in Java I'd probably have a movable object class and use that to create a player and asteroid class (each containing their respective, relevant functions).
So far, I succeeded to display the fractal when n = 1, but higher when it is higher than 1 it does not work at all.
n = 1
[IMG]http://imgur.com/CUS5o.png[/IMG]
n = 2
[IMG]http://imgur.com/sBTrQ.png[/IMG]
Here is my code to subdivise my square :
point2 is a typedef of GLFloat[2]
[CODE]void divide_square(point2 a, point2 b, point2 c, point2 d, int m)
{
point2 vertices[4];
point2 temp[4];
if(m>0)
{
int j;
for (j = 0; j < 2; j++)
{
vertices[0][j] = a[j] / 3;
vertices[1][j] = b[j] / 3;
vertices[2][j] = c[j] / 3;
vertices[3][j] = d[j] / 3;
}
float xdist = abs(b[0] - c[0]);
float ydist = abs(a[1] - b[1]);
std::cout << m << " " << xdist << " " << ydist << std::endl;
//carre 1
temp[0][0] = a[0] - xdist;
temp[0][1] = a[1] - ydist;
temp[1][0] = a[0] - xdist;
temp[1][1] = a[1];
temp[2][0] = a[0];
temp[2][1] = a[1];
temp[3][0] = a[0];
temp[3][1] = a[1] - ydist;
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 2
temp[0][0] = a[0] - xdist;
temp[0][1] = a[1];
temp[1][0] = b[0] - xdist;
temp[1][1] = b[1];
temp[2][0] = b[0];
temp[2][1] = b[1];
temp[3][0] = a[0];
temp[3][1] = a[1];
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 3
temp[0][0] = b[0] - xdist;
temp[0][1] = b[1];
temp[1][0] = b[0] - xdist;
temp[1][1] = b[1] + ydist;
temp[2][0] = b[0];
temp[2][1] = b[1] + ydist;
temp[3][0] = b[0];
temp[3][1] = b[1];
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 4
temp[0][0] = b[0];
temp[0][1] = b[1];
temp[1][0] = b[0];
temp[1][1] = b[1] + ydist;
temp[2][0] = c[0];
temp[2][1] = c[1] + ydist;
temp[3][0] = c[0];
temp[3][1] = c[1];
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 5
temp[0][0] = c[0];
temp[0][1] = c[1];
temp[1][0] = c[0];
temp[1][1] = c[1] + ydist;
temp[2][0] = c[0] + xdist;
temp[2][1] = c[1] + ydist;
temp[3][0] = c[0] + xdist;
temp[3][1] = c[1];
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 6
temp[0][0] = d[0];
temp[0][1] = d[1];
temp[1][0] = c[0];
temp[1][1] = c[1];
temp[2][0] = c[0] + xdist;
temp[2][1] = c[1];
temp[3][0] = d[0] + xdist;
temp[3][1] = d[1];
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 7
temp[0][0] = d[0];
temp[0][1] = d[1] - ydist;
temp[1][0] = d[0];
temp[1][1] = d[1];
temp[2][0] = d[0] + xdist;
temp[2][1] = d[1];
temp[3][0] = d[0] + xdist;
temp[3][1] = d[1] - ydist;
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
//carre 8
temp[0][0] = a[0];
temp[0][1] = a[1] - ydist;
temp[1][0] = a[0];
temp[1][1] = a[1];
temp[2][0] = d[0];
temp[2][1] = d[1];
temp[3][0] = d[0];
temp[3][1] = d[1] - ydist;
divide_square(temp[0],temp[1],temp[2],temp[3], m-1);
}
else
{
square(a,b,c,d); /* draw triangle at end of recursion */
}
}[/CODE]
Honestly, I don't understand much OpenGL and I don't know how to subdivise my square. Is some of my code is good, or am I totally wrong ?
And please forgive me. This code is horrible I know, but I'm only trying to make it work.
This is an odd problem.
I'm writing the Game Of Life in Java and at seemingly random times the KeyboardListener will not even function. Does anyone know of this issue? I can't replicate the issue and it seems to only happen on my laptop. My desktop is fine with it however.
Just wondering if anyone has seen this before. Its quite annoying.
Sorry, you need to Log In to post a reply to this thread.