Nice though maybe merging the 2 together would work well.
[QUOTE=neos300;26060792]try stringstream, and put #include <sstream> at the top.[/QUOTE]
I did include it, just tried using stringstream. same result...
[url]http://www.cplusplus.com/reference/iostream/stringstream/[/url]
[code]
// using stringstream constructors.
#include <iostream>
#include <sstream>
using namespace std;
int main () {
int val;
stringstream ss (stringstream::in | stringstream::out);
ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++)
{
ss >> val;
cout << val*2 << endl;
}
return 0;
}
[/code]
you may need to add std:: before it
Got that collision shit working:
[media]http://www.youtube.com/watch?v=OPmaL1cieSM[/media]
Next I need to detect when it's inside the shape and then pop it.
Nov. are there any gotcha's I need to look out for?
[editline]0[/editline]
Nobody's guessed where the eyes are from yet!
ok. ok. HOLD UP HERE. You want a "ToString()" method for a class? Don't write a "ToString", write an operator overload, which uses stringstreams behind the scenes.
[cpp]
#include <iostream>
#include <sstream>
#include <string>
struct vector3
{
explicit vector3(void) : x(0), y(0), z(0) { }
operator std::string(void)
{
std::ostringstream str;
str << "X: " << this->x << std::endl
<< "Y: " << this->y << std::endl
<< "Z: " << this->z << std::endl;
return str.str();
}
float x, y, z;
};
void print(const std::string& x) { std::cout << x << std::endl; }
int main(void)
{
vector3 x;
print(x);
}
[/cpp]
Now for some clarity, you can't directly send the vector3 to std::cout, BUT, you can send it through a function that takes a string, and this is due to std::string not having an explicit constructor, so C++ will try to find a const char*, or std::string operator overload, with which it will call to cast the object to said type.
Otherwise, if a type has an explicit constructor, you will need to use static_cast<>();
[cpp]
std::ostream& operator<< (std::ostream& out, const Vector3& vector)
{
return out << "X: " << vector.x << std::endl << "Y: " << vector.y << std::endl << "Z: " << vector.z << std::endl;
}
int main()
{
Vector3 w, t, f;
std::cout << w << t << f << std::endl;
}
[/cpp]
???
Or am I missing the point here?
[QUOTE=CarlBooth;26061453]Nov. are there any gotcha's I need to look out for?[/QUOTE]
Hmmmm...make sure the player can't jump over the shape boundary in one frame (check if they're touching the border then check if they were outside last frame but inside this frame). Also make sure you keep shape angles within 0-360 degrees or 0-2Pi radians.
If you store the state of the player relative to shapes (inside or outside) then make sure they're properly reset on the player death, so he can be spawned anywhere (even inside a shape) without dying more than once because the game thinks they've jumped over a border.
[QUOTE=layla;26062069]
Or am I missing the point here?[/QUOTE]
Yes. We're talking about a ToString() method, not specifically just printing to std::cout, though I was using it as an example. Assuming you wished to serialize a number of objects by either an std::fstream, or std::ostream, it would most likely be easier to write an operator std::string, rather than an overload for writing to both separately.
[QUOTE=NovembrDobby;26062338]Hmmmm...make sure the player can't jump over the shape boundary in one frame (check if they're touching the border then check if they were outside last frame but inside this frame). Also make sure you keep shape angles within 0-360 degrees or 0-2Pi radians.
If you store the state of the player relative to shapes (inside or outside) then make sure they're properly reset on the player death, so he can be spawned anywhere (even inside a shape) without dying more than once because the game thinks they've jumped over a border.[/QUOTE]
Cheers.
If I'm reading this correctly, we aren't looking to give a class a ToString method, we're just looking to concatenate an int (or similar numerical type) with a string, in which case this will do the job.
[cpp]
#include <sstream>
...
int playerscore;
std::stringstream ss;
std::string finalstring;
...
ss.str(""); //clear the string if you are reusing it
ss << "Player Score: " << playerscore;
finalstring = ss.str();
[/cpp]
Anyone know how to get the clipboard working in Mono
[QUOTE=Chandler;26062605]Assuming you wished to serialize a number of objects by either an std::fstream, or std::ostream, it would most likely be easier to write an operator std::string, rather than an overload for writing to both separately.[/QUOTE]
The fstream inherits from ostream, so if you implemented the operator for ostream, you would be able to output to any kind of ostream (fstream, stringstream, cout etc).
[QUOTE=CarlBooth;26061453]
Nobody's guessed where the eyes are from yet![/QUOTE]
Maybe looks like shoop the whoop?
[QUOTE=Vbits;26061033][url]http://www.cplusplus.com/reference/iostream/stringstream/[/url]
[code]
// using stringstream constructors.
#include <iostream>
#include <sstream>
using namespace std;
int main () {
int val;
stringstream ss (stringstream::in | stringstream::out);
ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++)
{
ss >> val;
cout << val*2 << endl;
}
return 0;
}
[/code]
you may need to add std:: before it[/QUOTE]
Thanks, but since I'm using SFML to draw my text, I need to convert it to even another format:
[code]>.\Main.cpp(143) : error C2664: 'sf::String::SetText' : cannot convert parameter 1 from 'std::stringstream' to 'const sf::Unicode::Text &'[/code]
Fudge.
[QUOTE=bean_xp;26064522]The fstream inherits from ostream, so if you implemented the operator for ostream, you would be able to output to any kind of ostream (fstream, stringstream, cout etc).[/QUOTE]
After a quick test, I have found you are correct. I recall however attempting to do that at some point, but for whatever reason, it failed to compile. Now this is going to bother me, because I know I had to abandon that route at some point in the past for a project, and I cannot remember why. :/
Hot damn gigedie, got lua to work!
[IMG]http://i.imgur.com/kXGyw.png[/IMG]
[code]
tbl = {}
tbl.Name = "Random"
tbl.SubName = "Trigger"
tbl.Type = "I/O"
function tbl.Initialize(gate)
-- gate is the gate ofc
gate.Name = "Random"
gate:SetSize(64, 32)
CreateGateOutput({gate = gate, y = 14, name = "Random"})
end
function tbl.OnClick(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the end of the mouseclick (on release)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.OnPress(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the start of the mouse click (on press)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.Update(gate)
-- gate is the gate ofc
-- update is called 60 times a second, (unless you have a penitum 2)
gate:SetOutput(1, math.Rand(0,1))
end
function tbl.Draw(gate)
-- gate is once again, the gate
local pos = Engine.Screen:WorldToScreen(gate.rectangle);
Engine.Surface:DrawBox(pos.X, pos.Y, pos.Width, pos.Height, Color(30,30,30,255));
Engine.Surface:SimpleText("Value: " .. gate:GetOutput(1), "Arial8", pos.X + (pos.Width / 2), pos.Y + (pos.Height / 2), Color(255,255,255,255), 1, 1)
end
RegisterGate(tbl)
[/code]
[QUOTE=bromvlieg;26065633]Hot damn gigedie, got lua to work!
[img_thumb]http://i.imgur.com/kXGyw.png[/img_thumb]
[code]
tbl = {}
tbl.Name = "Random"
tbl.SubName = "Trigger"
tbl.Type = "I/O"
function tbl.Initialize(gate)
-- gate is the gate ofc
gate.Name = "Random"
gate:SetSize(64, 32)
CreateGateOutput({gate = gate, y = 14, name = "Random"})
end
function tbl.OnClick(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the end of the mouseclick (on release)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.OnPress(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the start of the mouse click (on press)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.Update(gate)
-- gate is the gate ofc
-- update is called 60 times a second, (unless you have a penitum 2)
gate:SetOutput(1, math.Rand(0,1))
end
function tbl.Draw(gate)
-- gate is once again, the gate
local pos = Engine.Screen:WorldToScreen(gate.rectangle);
Engine.Surface:DrawBox(pos.X, pos.Y, pos.Width, pos.Height, Color(30,30,30,255));
Engine.Surface:SimpleText("Value: " .. gate:GetOutput(1), "Arial8", pos.X + (pos.Width / 2), pos.Y + (pos.Height / 2), Color(255,255,255,255), 1, 1)
end
RegisterGate(tbl)
[/code][/QUOTE]
inb4 grids
A couple of suggestions for your Lua interface.
[list][*]You should make the type an enumeration instead of a string.
[*]Use [i]function gate:Initialize()[/i] and refer to [i]self[/i] instead of what you're doing now.
[*]Make your functions more consistent. Why are the drawing functions in the table Engine.Surface and other functions global?[/list]
[QUOTE=bromvlieg;26065633]Hot damn gigedie, got lua to work!
[img_thumb]http://i.imgur.com/kXGyw.png[/img_thumb]
[code]
tbl = {}
tbl.Name = "Random"
tbl.SubName = "Trigger"
tbl.Type = "I/O"
function tbl.Initialize(gate)
-- gate is the gate ofc
gate.Name = "Random"
gate:SetSize(64, 32)
CreateGateOutput({gate = gate, y = 14, name = "Random"})
end
function tbl.OnClick(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the end of the mouseclick (on release)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.OnPress(gate, mouseX, mouseY)
-- gate is the gate ofc
-- this is called at the start of the mouse click (on press)
-- mouseX and mouseY are counted from the left top of the gate, so it wil be between 0-size, left top wil be 0
-- gate is the gate itself, Doh
end
function tbl.Update(gate)
-- gate is the gate ofc
-- update is called 60 times a second, (unless you have a penitum 2)
gate:SetOutput(1, math.Rand(0,1))
end
function tbl.Draw(gate)
-- gate is once again, the gate
local pos = Engine.Screen:WorldToScreen(gate.rectangle);
Engine.Surface:DrawBox(pos.X, pos.Y, pos.Width, pos.Height, Color(30,30,30,255));
Engine.Surface:SimpleText("Value: " .. gate:GetOutput(1), "Arial8", pos.X + (pos.Width / 2), pos.Y + (pos.Height / 2), Color(255,255,255,255), 1, 1)
end
RegisterGate(tbl)
[/code][/QUOTE]
You mispelled "wiring", by the way. It's kind of nit-picky, but the caps are a little inconsistent as well.
...
Damn. Now it seems like I'm just focusing on the negatives. :saddowns:
I decided to record myself programming for 48 minutes.
[media]http://www.youtube.com/watch?v=_tODgSEtHCg[/media]
It may be low quality, I just uploaded so you may need to wait a few minutes to be able to watch it in HD.
Have you given up on zombie outrage?
[QUOTE=Richy19;26065940]Have you given up on zombie outrage?[/QUOTE]
Not completely, I'll still add on to it. But it switched to my side project and now Beat Tapper is my main one. Later on it'll switch back and reverse rolls where Beat Tapper is on the side and Zombie Outrage 2 is the main one.
It's just to keep me switching so I don't get bored of the same thing over and over again. ;)
[img]http://gyazo.com/655aa3b194516a8d63a68018292bbd53.png[/img]
[img]http://gyazo.com/84f9657619bf13fbe2559445e3aff794.png[/img]
:v:
Edit: Not sure why the timer is 0:00 on the screenshot...
[editline]15th November 2010[/editline]
[QUOTE=xAustechx;26065887]I decided to record myself programming for 48 minutes.
[media]http://www.youtube.com/watch?v=_tODgSEtHCg[/media]
It may be low quality, I just uploaded so you may need to wait a few minutes to be able to watch it in HD.[/QUOTE]
I like watching these for some reason.
[QUOTE=Chandler;26061523]ok. ok. HOLD UP HERE. You want a "ToString()" method for a class? Don't write a "ToString", write an operator overload, which uses stringstreams behind the scenes.
[cpp]
#include <iostream>
#include <sstream>
#include <string>
struct vector3
{
explicit vector3(void) : x(0), y(0), z(0) { }
operator std::string(void)
{
std::ostringstream str;
str << "X: " << this->x << std::endl
<< "Y: " << this->y << std::endl
<< "Z: " << this->z << std::endl;
return str.str();
}
float x, y, z;
};
void print(const std::string& x) { std::cout << x << std::endl; }
int main(void)
{
vector3 x;
print(x);
}
[/cpp]
Now for some clarity, you can't directly send the vector3 to std::cout, BUT, you can send it through a function that takes a string, and this is due to std::string not having an explicit constructor, so C++ will try to find a const char*, or std::string operator overload, with which it will call to cast the object to said type.
Otherwise, if a type has an explicit constructor, you will need to use static_cast<>();[/QUOTE] This seems hacky as all fuck.
[QUOTE=BlkDucky;26066251][img_thumb]http://gyazo.com/655aa3b194516a8d63a68018292bbd53.png[/img_thumb]
[img_thumb]http://gyazo.com/84f9657619bf13fbe2559445e3aff794.png[/img_thumb]
:v:
Edit: Not sure why the timer is 0:00 on the screenshot...
[editline]15th November 2010[/editline]
I like watching these for some reason.
[editline]15th November 2010[/editline]
I like watching these for some reason.[/QUOTE]
ROFL, You found the secret message. :v:
[QUOTE=Overv;26065786]A couple of suggestions for your Lua interface.
[list]
[*]Use [i]function gate:Initialize()[/i] and refer to [i]self[/i] instead of what you're doing now.
[/list]
[/QUOTE]
How does that work in C#, do i call the lua function the same way, but is the first arg converted to self? or do i need to use a special way?
[QUOTE=xAustechx;26065887]I decided to record myself programming for 48 minutes.
[media]http://www.youtube.com/watch?v=_tODgSEtHCg[/media]
It may be low quality, I just uploaded so you may need to wait a few minutes to be able to watch it in HD.[/QUOTE]
You should have recorded for 44 Minutes.
[media]http://www.youtube.com/watch?v=OL7DED8huak[/media]
So I'm currently using Code::Blocks as my C++ ide. Do you guys recommend VS2010 as my new ide? I really like the C# version also.
[QUOTE=neos300;26068264]So I'm currently using Code::Blocks as my C++ ide. Do you guys recommend VS2010 as my new ide? I really like the C# version also.[/QUOTE]
yes
[QUOTE=i300;26068063]You should have recorded for 44 Minutes.
[media]http://www.youtube.com/watch?v=OL7DED8huak[/media][/QUOTE]
That song isn't long enough to cover the the length of my video. So I guess you could say
This song, doesn't, live up to it's name.
[media]http://www.solarnavigator.net/films_movies_actors/film_images/Austin_Danger_Powers_Mike_Myers.jpg[/media]
Sorry, you need to Log In to post a reply to this thread.