• Create Account

# nimrodson

Member Since 13 Feb 2012
Offline Last Active Private

### #5050656Traversing a List of Vectors

Posted by on 06 April 2013 - 02:13 PM

If you're using C++11, you can try this too:

```#include <vector>
#include <list>
#include <iostream>

int main()
{
std::list<std::vector<int>> listVectors{{1,2,3},{4,5,6},{7,8,9}};
for ( auto& vec : listVectors )
for ( int& i : vec )
//process each int i
std::cout << i << std::endl;
}

```

### #5048952Three of a kind numbers

Posted by on 01 April 2013 - 02:20 PM

Just for fun, a (beginner) Haskell implementation:

```unique :: (Eq a) => [a] -> [a]
unique []     = []
unique (x:xs) = x : unique (filter (\y -> not (x==y)) xs)

nOcurrences :: (Eq a) => a -> [a] -> Int
nOcurrences elem list = length (filter (==elem) list)

isThreeKind :: (Eq a) => [a] -> Bool
isThreeKind list = elem 3 [nOcurrences i list | i <- (unique list)]

```

You could parametrize the 3 number in "isThreeKind" function and have a "fourKind", a "fiveKind", or whatever...

Cheers.

### #5048034Object was not declared in this scope?

Posted by on 29 March 2013 - 10:39 AM

When you doing this:

// creating the object
if(event.button.button==SDL_BUTTON_LEFT) bullet myBullet(90, 530, 20, -20, 1);

You're using *automatic* (EDITED, thanks @rip-off. Don't confuse with "auto" C++11 reserved word) declaration -> allocation on the variable "myBullet". That means (among other things) that the "myBullet" timelife remains in the scope in which that variable was declared, in this case, the precedent if statement. When the if statement is consumed, all the *automatic* resources inside the "if" scope are destroyed, including "myBullet". That is the reason why "myBullet.update()" is undefined, because there's no declaration of "myBullet" in the present scope or an outter scope (When you comment out the first line, myBullet declaration, this is in a outter scope, and therefore works).
What you need to do is using dynamic allocation, something like the solutions presented by the others members.

### #5048024What is functional programming and how can it help us in game developing?

Posted by on 29 March 2013 - 10:19 AM

Using compute shaders is functional programming. Functional programming and associated languages usually map better to hardware (think FPGAs) than software. Come to think of it, any shader is a functional program evaluated simultaneously on blocks of data.

OK, thanks for the tip. But, what happens in a higher abstraction level? Which elements of functional programming could be beneficious in game design?

Newly, thanks.

### #5047852What is functional programming and how can it help us in game developing?

Posted by on 28 March 2013 - 09:29 PM

Hi,

I would like to know some opinions about this programming paradigm: It is useful? How much? Could have an important role or participation in game design and/or coding? It is complementary, opposite, or totally uncomparable to OOP?

Thanks.

### #5028518What is the difference between "Entity" and "Sprite"?

Posted by on 03 February 2013 - 09:04 PM

Just that. Thanks.

PARTNERS