I'm back with another brain-dead question.
So, I have this test file in a folder called 'Test'. The file looks like this.
[code]HC = require 'HardonCollider'
Collider = HC(100, on_collision, collision_stop)
local Test = {}
function Test.newBox(x, y, drawable)
love.graphics.draw(drawable, x, y)
local width, height = drawable:getDimensions()
Collider.addRectangle(x, y, width, height)
end[/code]
Then, in the main lua file (I'm using Love2D, by the way), I try to use the Test.newBox function.
[code]HC = require 'HardonCollider'
Tap0 = require 'Test'
function love.load()
-- Initialize HardonCollider
Collider = HC(100, on_collision, collision_stop)
grassTile = love.graphics.newImage("grass.png")
map = {
{1,0,1,0,1,0,1,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,0,1,0,1,0,0,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1}
}
end
function love.update(dt)
end
function love.draw()
coordx = 0
coordy = 0
for y = 1, #map, 1 do
for x = 1, #map[y], 1 do
if map[y][x] == 1 then
coordx = x - 1
coordy = y - 1
Test.NewBox(coordx * 64, coordy * 64, grassTile)
end
end
end
end[/code]
When I try to use all of this, I get this error.
[code]Error
main.lua:37: attempt to index global 'Test' (a boolean value)
Traceback
main.lua:37: in function 'draw'
[C]: in function 'xpcall'[/code]
I realize this would be more fitting at the Love2d forum, but the problem doesn't feel too Love2d-specific.
Sorry about the long post. :words:
So I'm working on a tile-based Roguelike in Love2D and I want to have a procedurally generated map but I'm not sure where to even start. I was considering generating it in chunks but it doesn't seem like that'd work with room and hallway generation etc.
[QUOTE=BackwardSpy;44927253]Ah, I forgot to pass in a value for the 'side' parameter, you're right. Thanks a lot for your help!
I started adding those because for some reason it wasn't figuring them out properly earlier, though that may have been the result of an error somewhere. I'll start removing them again and see how far I get.
Thanks again. :)
[editline]28th May 2014[/editline]
Hm, the type inference works for everything that isn't SFML .NET's Vector2f type. Is this something I'm doing wrong, or is it due to the nature of referenced binaries or whatever?[/QUOTE]
It sometimes doesn't notice until you recompile, but if doesn't manage to do it then there's probably some other strangeness involved.
[QUOTE=Tamschi;44930535]It sometimes doesn't notice until you recompile, but if doesn't manage to do it then there's probably some other strangeness involved.[/QUOTE]
Ah well, it's not a huge issue so I'll worry about it later. The code is done now, albeit not working correctly. This has been a very interesting project so far, and I have to say I'm quite enjoying F#; it's a nice change of pace from what I'm used to.
My interface.
[CODE] public interface BagInterface<T> {
public BagInterface union(BagInterface anotherBag);
/**
* Creates a new bag that contains those objects that occur in both this bag
* and anotherBag.
*
* @paResizeableArrayBagag the bag thaResizeableArrayBagompared
* @return a combined bag
*/
}
[/CODE]
[CODE]
public class ResizableArrayBag<T> implements BagInterface<T> {
private T[] bag; // cannot be final due to doubling
private static final int DEFAULT_INITIAL_CAPACITY = 25; // initial capcity of bag
private int numberOfEntries;
/**
* Creates an empty bag whose initial capacity is 25.
*/
public ResizableArrayBag() {
this(DEFAULT_INITIAL_CAPACITY);
} // end default constructor
/**
* Creates an empty bag having a given initial capacity.
*
* @param capacity the integer capacity desired
*/
public ResizableArrayBag(int capacity) {
numberOfEntries = 0;
// the cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
T[] tempBag = (T[]) new Object[capacity]; // unchecked cast
bag = tempBag;
} // end constructor
/**
* Creates a bag containing given entries.
*
* @param contents an array of objects
*/
public ResizableArrayBag(T[] contents) {
bag = Arrays.copyOf(contents, contents.length);
numberOfEntries = contents.length;
} // end constructor
public BagInterface union(BagInterface anotherBag) {
int totalLen = numberOfEntries + anotherBag.getCurrentSize();
T[] union = (T[]) new Object[totalLen];
for (int i = 0; i < totalLen; i++) {
if (!this.isEmpty()) {
union[i] = bag[i];
} else if (!anotherBag.isEmpty()) {
union[i] = (T) anotherBag.get(i);
}
}
return union;
}[/CODE]
How do I return an interface?
[QUOTE=blacksam;44941232]How do I return an interface?[/QUOTE]
You can't return just an interface. What you do is return an object that implements that interface. In your code ResizableArrayBag implements BagInterface, so you would be able to return a ResizableArrayBag from the union function.
Just as a side note, the documentation of union makes it looks like it should actually return the intersection. Union is the set of elements present in either set, not both.
[QUOTE=blacksam;44941232]
[CODE]
/**
* [...]
* @paResizeableArrayBagag the bag thaResizeableArrayBagompared
* [...]
*/
}
[/CODE]
[/QUOTE]
*snrrrk*
[QUOTE=Fredo;44941583]You can't return just an interface. What you do is return an object that implements that interface. In your code ResizableArrayBag implements BagInterface, so you would be able to return a ResizableArrayBag from the union function.
Just as a side note, the documentation of union makes it looks like it should actually return the intersection. Union is the set of elements present in either set, not both.[/QUOTE]
Alright, thanks!
Yeah none of this is my documentation at all. It's from the book Data Structures and Abstractions in Java. My professor just gave us the files and told us to make it work.
Okay, so I've posted here a couple of times asking for tad bits of information on how to start learning to code, and I never really took the advice and put of things. Now I'm wanting to really strap down, focus and begin to learn how program.
I basically just want to know where to start, some good books, programs I might need, etc. Anything that can help me progress in my goal of learning to program will really be beneficial. I take a Computer Science class in my high school, but I've barely payed attention. We use XNA and code in C# making basic games, but because of my lack of focus in that class, I barely know how to do anything.
Again, any information on how to about starting, and actually learning how to code would be really helpful. Like I said; books, programs, videos, anything. Thanks.
[QUOTE=Exigent;44944509]Okay, so I've posted here a couple of times asking for tad bits of information on how to start learning to code, and I never really took the advice and put of things. Now I'm wanting to really strap down, focus and begin to learn how program.
I basically just want to know where to start, some good books, programs I might need, etc. Anything that can help me progress in my goal of learning to program will really be beneficial. I take a Computer Science class in my high school, but I've barely payed attention. We use XNA and code in C# making basic games, but because of my lack of focus in that class, I barely know how to do anything.
Again, any information on how to about starting, and actually learning how to code would be really helpful. Like I said; books, programs, videos, anything. Thanks.[/QUOTE]
I've never used XNA, but these seem like they can be useful:
[url]http://www.riemers.net/[/url]
[url]http://rbwhitaker.wikidot.com/xna-tutorials[/url]
[url]http://www.xnadevelopment.com/tutorials.shtml[/url]
[url]http://msdn.microsoft.com/en-us/library/bb203893.aspx[/url]
Here's some on C#:
[url]http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx[/url]
[url]http://www.tutorialspoint.com/csharp/[/url]
[url]http://www.csharp-station.com/tutorial.aspx[/url]
Thenewboston also has a collection of 200-ish videos on C#: [url]http://thenewboston.org/list.php?cat=15[/url]
Not just specifically C#, but like whatever would be best for someone new to this. I find programming really interesting and fun, I just have no idea on what to do. I'll check out those links.
Any other suggestions are still welcome though.
Okay, noob question. I kind of jumped into Lua half-way in. I have a question that has literally no super-basic answer, what the hell does a metatable do? Like, what EXACTLY does it do, why is it necessary, etc.
I've looked at tutorials but none of them made a lick of sense. You can call me stupid all you want, I just REALLY need to know.
[QUOTE=MilkBiscuit;44946340]Okay, noob question. I kind of jumped into Lua half-way in. I have a question that has literally no super-basic answer, what the hell does a metatable do? Like, what EXACTLY does it do, why is it necessary, etc.
I've looked at tutorials but none of them made a lick of sense. You can call me stupid all you want, I just REALLY need to know.[/QUOTE]
Metatables can get confusing. Just think of them as tables that tell Lua how to handle other tables.
When you perform an operation on a table, such as any of the mathematical operations, comparisons, concatenation, indexing, assignment, and calling, Lua checks a table's metatable for a function called a metamethod corresponding to the operation. If it finds the metamethod it's looking for, it will call that function instead of performing the default operation. This is useful, for example, if you want to create a table that can only contain strings:
[code]local stringTable = {}
local mt = {}
function mt.__newindex(t, key, value)
assert(type(value) == "string", "stringTable can only contain strings!")
rawset(t, key, value)
end
setmetatable(stringTable, mt)
stringTable[1] = "test"
stringTable.notAString = 42[/code]
Here, we define stringTable, define the metatable, and define the metatamethod __newindex in the metatable. Up to this point, the metatable is useless because it's not associated with stringTable, so we call setmetatable with stringTable and the metatable to associate them. A metatable can be associated with any number of tables, but a table can only have one metatable.
From any point after the metatable is set, you should be unable to set any key in stringTable to anything but a string without causing the assertion in mt.__newindex to fail or without using rawset. (Unfortunately, table.insert does not call the __newindex metamethod.)
Another use for metatables is their ability to define what a table will do if it is called like a function. Such tables are sometimes called functables.
For this example, let's create a table named Bob. Bob will have some information about himself such as his age and his favorite color and calling Bob will make him say it.
[code]Bob = {}
Bob.age = 36
Bob.favoriteColor = "Green"
mt = {}
function mt.__call(table, ...)
print("I am " .. table.age .. " years old and my favorite color is " .. table.favoriteColor .. "!")
end
setmetatable(Bob, mt)
Bob()[/code]
I hope this is a good enough explanation. If I'm wrong or misleading, somebody correct me.
Does anyone know how to see which files are being tested for existence when an executable tries to resolve its DLLs on Windows 8? I remember doing that a few months ago, but can't find the instructions for how to do so again.
[QUOTE=Ziks;44949818]Does anyone know how to see which files are being tested for existence when an executable tries to resolve its DLLs on Windows 8? I remember doing that a few months ago, but can't find the instructions for how to do so again.[/QUOTE]
.NET or C++? In .NET there's an event in AppDomain.
[QUOTE=Tamschi;44950162].NET or C++? In .NET there's an event in AppDomain.[/QUOTE]
I think it's more of a Windows system event thing, which lists all paths a process tests for existence (not just for DLL resolution). It might have been through the Event Viewer with a certain set of filters, but it doesn't look familiar. Technically I don't need it any more anyway, I found the source of an issue I was having.
[QUOTE=Ziks;44950595]I think it's more of a Windows system event thing, which lists all paths a process tests for existence (not just for DLL resolution). It might have been through the Event Viewer with a certain set of filters, but it doesn't look familiar. Technically I don't need it any more anyway, I found the source of an issue I was having.[/QUOTE]
[URL="http://technet.microsoft.com/de-de/sysinternals/bb896645.aspx"]Proecess Monitor[/URL] can do that I think.
[QUOTE=Tamschi;44951708][URL="http://technet.microsoft.com/de-de/sysinternals/bb896645.aspx"]Proecess Monitor[/URL] can do that I think.[/QUOTE]
That looks right, thanks!
How do I calculate the normal values for glNormal3f? Is my terrain coming up fullbright because I'm not using it?
[t]http://i.imgur.com/1WWZP3Y.png[/t]
My terrain is drawn using this code:
[code]void HMap::draw() {
z -= 0.2;
// Set up matrix for transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(x, y, -z); // Translate to player position
glBindTexture(GL_TEXTURE_2D, textTest2);
glBegin(GL_TRIANGLE_STRIP);
for (int z = 0; z < w - 1; z++) {
for (int x = 0; x < w; x++) {
glVertex3f(x, getHeight(x, z), z);
glVertex3f(x, getHeight(x, z + 1), z + 1);
}
}
glPopMatrix();
glEnd();
}[/code]
[editline]31st May 2014[/editline]
Also how would I go about texturing my terrain?
[QUOTE=Pat.Lithium;44958150]How do I calculate the normal values for glNormal3f? Is my terrain coming up fullbright because I'm not using it?
[t]http://i.imgur.com/1WWZP3Y.png[/t]
My terrain is drawn using this code:
[code]void HMap::draw() {
z -= 0.2;
// Set up matrix for transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(x, y, -z); // Translate to player position
glBindTexture(GL_TEXTURE_2D, textTest2);
glBegin(GL_TRIANGLE_STRIP);
for (int z = 0; z < w - 1; z++) {
for (int x = 0; x < w; x++) {
glVertex3f(x, getHeight(x, z), z);
glVertex3f(x, getHeight(x, z + 1), z + 1);
}
}
glPopMatrix();
glEnd();
}[/code]
[editline]31st May 2014[/editline]
Also how would I go about texturing my terrain?[/QUOTE]
There are other ways, but in a general case you can get the normal vector for a polygon by taking the [url=http://en.wikipedia.org/wiki/Cross_product]cross product[/url] of two perpendicular sides.
I got the texturing working if it tiles across the terrain, how do I make it stretch one texture over the whole terrain?
[t]http://i.imgur.com/dUAfEXD.png[/t]
[code]void HMap::draw() {
z -= 0.2;
if (z < 0) z = 500;
// Set up matrix for transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(x, y, -z); // Translate to player position
glBindTexture(GL_TEXTURE_2D, skyTex);
glBegin(GL_TRIANGLE_STRIP);
float tx = 0, ty = 0, inc = 1;
for (int z = 0; z < w - 1; z++) {
for (int x = 0; x < w; x++) {
glTexCoord2f(tx, ty); glVertex3f(x, getHeight(x, z), z);
glTexCoord2f(tx, ty + inc); glVertex3f(x, getHeight(x, z + 1), z + 1);
tx += inc;
}
ty += inc;
}
glPopMatrix();
glEnd();
}[/code]
you are drawing a 2 dimensional matrix of vertices for your terrain...
just stretch the texcoords over the whole matrix instead of using the same texcoords for every quad.
so if you have 50*50 terrain matrix
your texcoords should be for x: 0 - 1 or more mathematical: nx = count of x polys and ix = the i-th vertex
ix/nx should be the texcoord for the i-th vertex on the x axis
same for the y coord but there you start from 1 and go towards 0
if you start to draw the mesh from upper left corner.... ofcourse :D
openGL texcoords have their 0.0 point in the lower left corner if i remember right.
So I've been researching and attempting to hook the memory from an external Lua process into an injected dll. My goal is to be able to push my own Lua code into another application's Lua State.
I found someone who was trying to do something similar, but the answer doesn't help me out.
[url]http://stackoverflow.com/questions/16012379/getting-address-of-lua-state-pointer-to-get-result-in-outer-program[/url]
I'm using the default lua.exe 5.1 application and I've been through ollydbg and IDA trying to find memory addresses to the state. I'm fairly new to reverse engineering and I've come to a point where I have nofuckinclue where I could get this address.
My IDA shows that the main function invokes the state here:
[t]http://up.nlan.org/RgVn.png[/t]
My ollydbg debugging the process shows the luaL_newstate here:
[t]http://up.nlan.org/e.png[/t]
If anyone can help me out, I'd greatly appreciate it. I just don't understand where my state would be stored. If it helps, here's my dll code that I'm going to be using.
[code]
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <iostream>
extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
void __stdcall CallFunction();
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: {
printf("DLL connected to process, initializing Lua State...\n");
printf("lex loadstring set, attempting to pass args.");
lua_State *L = (lua_State*)0x004020F7;
if (L)
{
printf("- lua_State obtained, attempting to set data..\n");
lua_pushstring(L, "100");
lua_setglobal(L, "test");
printf("- set _G.test = \"100\"");
}
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
[/code]
[editline]31st May 2014[/editline]
wait i think i solved it holy shit
[img]http://up.nlan.org/lRCegg.png[/img]
in ollydbg it traced the address when i highlighted the mov woo
I'm so fucking frustrated with c++. I keep trying to do a simple task and get horribly bogged down in misusing types, not knowing how to convert from type to type, and not even knowing what I'm doing because I'm just trying to get something to work. [url=http://projecteuler.net/problem=11]this problem[/url] is way too fucking hard. If I can't do a simple problem like this, then I can't move on.
[editline]1st June 2014[/editline]
Can someone give me some tips on managing a problem like that, instead of diving in head first and getting shit on and frustated as fuck by menial smaller problems?
[QUOTE=NixNax123;44969802]I'm so fucking frustrated with c++. I keep trying to do a simple task and get horribly bogged down in misusing types, not knowing how to convert from type to type, and not even knowing what I'm doing because I'm just trying to get something to work. [url=http://projecteuler.net/problem=11]this problem[/url] is way too fucking hard. If I can't do a simple problem like this, then I can't move on.
[editline]1st June 2014[/editline]
Can someone give me some tips on managing a problem like that, instead of diving in head first and getting shit on and frustated as fuck by menial smaller problems?[/QUOTE]
I wouldn't call that a simple problem. It certainly takes some thinking and I wouldn't expect a beginner to come up with a solution very quickly.
The way to go about solving problems like this is to first focus on [i]what[/i] you want to do to solve the it (think in terms of algorithms, not C++ statements. Maybe write some pseudo code), and then work on [i]how[/i] you are going to solve it (convert that pseudo code into real code).
This problem involves a grid of numbers, so you obviously need some way to store them. I'd recomment a 2-dimensional array (an array of arrays), preferably using C++'s vector container. The type would be std::vector<std::vector<int> > (a vector of vectors of ints).
Then focus on how to want to get the adjacent numbers. Basically you want to loop over each element and look in 8 directions from it (though you can optimize this to 4). You also want to keep track of the maximum product (this should be simple).
[QUOTE=NixNax123;44969802]I'm so fucking frustrated with c++. I keep trying to do a simple task and get horribly bogged down in misusing types, not knowing how to convert from type to type, and not even knowing what I'm doing because I'm just trying to get something to work. [url=http://projecteuler.net/problem=11]this problem[/url] is way too fucking hard. If I can't do a simple problem like this, then I can't move on.
[editline]1st June 2014[/editline]
Can someone give me some tips on managing a problem like that, instead of diving in head first and getting shit on and frustated as fuck by menial smaller problems?[/QUOTE]
I think most, if not all, Project Euler problems (didn't do a lot of them) have approaches that range from brute force to genius maths trickery.
E.g. for the sum of integers problem you can do it with brute force with a loop, or refrain from programming and figure out a simple algebraic expression (n*(n-1)/2 or something like that). The brute force approach requires more complex programming than the mathematical approach.
I suspect this is the case for most (if not all) PE problems, try to simplify the problem with maths to avoid making your code complex and inefficient. Figure out patterns, properties. And as stated above, figure out an algorithm that you think will work before you start programming. Too often I implemented shit for days to come to the conclusion it never would have worked in the first place.
Oh and uh, Project Euler problems are by no means simple imho :v: Here I'd try to figure out an expression that allows you to fetch those elements in each product (for some element (i,j)). You'll see that the location of those elements should just depend on the orientation (up down, diagonal, whatever..) and the array dimensions, and the index (i,j). From there you can easily compute the product for each element. You'll also need some conditional statements to avoid reading outside of the array. You could first ignore that by just iterating over the "inner" elements that allow any possible product. After that you can extend your code to deal with the edges. As for data type: anything that can represent a matrix and allows you to fetch an element for some index (i,j) (or linear index k=i*N+j or something like that) should be able to do the job. My tips might be badly worded or just plain wrong, I should actually try it myself to see if I'm not just selling gibberish.
First figure out the general outline of your solution and try to divide the problem into smaller parts that are not hard by themselves.
[QUOTE=Number-41;44972044]I think most, if not all, Project Euler problems (didn't do a lot of them) have approaches that range from brute force to genius maths trickery.
E.g. for the sum of integers problem you can do it with brute force with a loop, or refrain from programming and figure out a simple algebraic expression (n*(n-1)/2 or something like that). The brute force approach requires more complex programming than the mathematical approach.
I suspect this is the case for most (if not all) PE problems, try to simplify the problem with maths to avoid making your code complex and inefficient. Figure out patterns, properties. And as stated above, figure out an algorithm that you think will work before you start programming. Too often I implemented shit for days to come to the conclusion it never would have worked in the first place.
Oh and uh, Project Euler problems are by no means simple imho :v: Here I'd try to figure out an expression that allows you to fetch those elements in each product (for some element (i,j)). You'll see that the location of those elements should just depend on the orientation (up down, diagonal, whatever..) and the array dimensions, and the index (i,j). From there you can easily compute the product for each element. You'll also need some conditional statements to avoid reading outside of the array. You could first ignore that by just iterating over the "inner" elements that allow any possible product. After that you can extend your code to deal with the edges. As for data type: anything that can represent a matrix and allows you to fetch an element for some index (i,j) (or linear index k=i*N+j or something like that) should be able to do the job. My tips might be badly worded or just plain wrong, I should actually try it myself to see if I'm not just selling gibberish.
First figure out the general outline of your solution and try to divide the problem into smaller parts that are not hard by themselves.[/QUOTE]
Thanks for the support, it helps a lot.
I know that's what the problem boils down to, and I can figure out the maths for computing the products, but I just can't divide the grid into numbers. Nevertheless try to get bounds checking to work with products.
Oh the intricacies of templates in C++ make me want to kill myself. How do I properly define a templated function as being a friend function to another class? The function is as follow:
[cpp]template <class T, typename ... Args>
void addComponent(Args&&... args)[/cpp]
It's in the class Entity. Really not sure how to go about this.
[cpp]
template<class T, typename... Args>
friend void addComponent(Args&&... args);
[/cpp]
Generally speaking, you just copy the declaration and add "friend" to it.
See I did that, but I got
[code]cmodel.h(8): fatal error C1001: An internal error has occurred in the compiler.[/code]
Sorry, you need to Log In to post a reply to this thread.