Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 58 59 [60] 61 62 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100655 times)

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #885 on: October 17, 2012, 05:07:40 am »

I wasn't including the stories branching in 'playable' :)
Sure all the content would add a lot, but the basic playable would just be the settlement and ui I imagine, and the simpler random events around that. Just enough that you can see how it will take shape and get feedback from people really.

The stories themselves you could just pull directly out as text, but the art work associated with them would be more effort. You'd at least want higher resolution versions.
If you wanted to make your own stories that were just as interesting then your adding significant time to the task.

Also I'm a programmer, I always underestimate tasks. I should really at least double anything I quote.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Singularity-SRX

  • Bay Watcher
  • *shudders*
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #886 on: October 17, 2012, 06:13:23 am »

Hey again guys, sorry to butt in ahahah
I to reply to the previous posts, the idea to make the formula smaller( B.Mass/dist^2), although it works, I want to keep the vars in there in case I want to display them later.
Also, I looked into OpenGL and it looks confusing as hell ahahaha, not saying that I won't try it at some point but just not at the current moment.

Right now I'm going through the process of re-writing some of the code (namely, the generation code)
Here it is, it's not put into the actual program yet, and is separate from the whole thing. (i.e. anything that isn't inside of the generate function is considered to be in main())
Code: [Select]
int menuchoice;
int simloop;
int nop;

cout << "Welcome to gravsim 0.2" << endl << endl;
cout << "Please choost an option below:" <<endl;
cout << "1) Generate" << endl
cout << "2) Exit" << endl;
cin >> menuchoice;

if (menuchoice == 1)
{
cout << "Please choose method of generation: " << endl;
cout << "1) Random Generation" << endl;
cout << "2) Manual Generation" << endl;
cin >> menuchoice;

if(menuchoice == 1)
{
simloop = 50;
nop = 3;
}else{
cout << "Please enter the number of planets to simulate:" << endl;
cin >> nop;
cout << "Please enter the number of times for the simulation to run: "<<endl;
cin >> simloop;
}
Generate(menuchoice, nop);
}else{
end;
}

int Generate(int a, int nop)
{
float genX;
float genY;
int genMass;
float genSpeedx;
float genSpeedy;

for(int g=0;g<nop;g++)
{
if (a == 1)
{
genX = rand() % 500 + 1;
genY = rand() % 500 + 1;
genMass = rand() % 50 + 2;
genSpeedx = rand() % 5 + 1;
genSpeedy = rand() % 5 + 1;
}else{
cout << "Planet: "<<g+1<<"'s x: "; cin >> genX;
cout << "Planet: "<<g+1<<"'s y: "; cin >> genY;
cout << "Planet: "<<g+1<<"'s xspeed: "; cin >> genSpeedx;
cout << "Planet: "<<g+1<<"'s yspeed: "; cin >> genSpeedy;
cout << "Planet: "<<g+1<<"'s mass: "; cin >> genMass;
}

planet[g].x = genX;
planet[g].y = genY;
planet[g].xspeed = genSpeedx;
planet[g].yspeed = genSpeedy;
planet[g].mass = genMass;
planet[g].xacc = 0;
planet[g].yacc = 0;
}
}

The new code uses a function to generate instead of having it all inside of int main().
Some questions that I've realized are that:
a) I'm pretty sure I'm gonna need the struct(planet) inside of int main, then use it as an argument in the function, and
b) How do I return a structure array? (I.e. one that uses variables other then just 'Int' and then
c) Also is this bad coding practice or is there a better way of doing this?

One more question was that of how to reverse the x and y speeds into the angle that it's heading.
i.e. if xspeed = cos(angle)*xacc and yspeed = sin(angle)*yacc
Without using the angle variable in the Value loop
Logged
Quote from: Vertigon
slamming his left hand into the baby's face
I came to this forum with no intention of ever uttering that phrase.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #887 on: October 17, 2012, 07:02:41 am »

Q (a) isn't really a question ...

Q (b) : To return a structure is the same as returning any other variable. The function type is myStructure myfunction(); . You write return myStructureVariableName; .
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #888 on: October 17, 2012, 08:27:15 am »

OpenGL does most of it for you essentially, for example with the MSAA extension you literally use one command to turn on anti aliasing and one to turn it off.
I'm really behind the curve on OpenGL, I'll admit.  When I've got something that works, I use it.  I've no idea if you could even get a fill triangle (say) with one AAed side and two non-AAed sides[1]...  But then I'm sometimes a control-freak, like that, and I can't think of many reasons for other people to want such a graphical output, only my own rather obscure ones.

Anyway, if anyone wants any wheels re-inventing, please do feel free to let me know.  I have a special deal on triangular ones, at the moment.  ;)


[1] Of course you probably could.  Draw an AAed triangle and then re-draw the unAAable sides unAAed.  Hmm, unless there's pixel-leak.  Might have to undraw a line one pixel further out as well, to resharpen it.  Still, probably possible.  I just think at too low a level, sometimes.
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #889 on: October 17, 2012, 08:53:51 am »

The code would be really simple if you ask me. The hardest part, for me, would be the art work and making it all look nice.
edit: quoting levels corrected

Never played King Of Dragon Pass (not, that I recall, even heard of it... which probably says something about me).

But.  Back in the day (decades ago) I put an entire Fighting Fantasy book onto a microcomputer (without its pictures).  Coding for that was fairly simple, and most of the hard work was the data entry.

Each story text already had a number assigned to it, and (unless a win/lose condition page) had one or more numbers that you could then follow onwards to (explicitly or otherwise).  So I stored each 'page' number, the text it gives and the choices (if any), plus details about any special conditions[1], and I suppose I could have stored details of how to draw pictures.  The basic code (in fact, it was BASIC code!) just repeatedly assessed the 'current page', output what it needed to, dealt with any calculations that were necessary[2].  Changing it to reflect a second FF book's "plotline" would have been fairly easy (just tedious) in getting the information input and perhaps an enhancement of the basic engine to add something that the second book needed that I hadn't needed for the first[3].

Which is basically the approach that I suspect a lot of branching-plot games-engines follow, like SCUMM/ScummVM.

These days, I'd probably even just re-do it in HTML, with a little bit of scripting (either server-side or client-side, according to taste) where necessary, but this was a pre-web era I was talking about.  (Also prior to my being on the Internet, and didn't have too many people with whom I could share the save-tapes of my creations, so it was for my fun and enjoyment alone (mostly, in the creating, rather than the playing), and no real chance that I'd be sued for copyright over the content I'd 'stolen', from the book that I owned but was still not allowed to "duplicate electronically or physically", or whatever the phrase was.  The question arises whether I could have developed my own adventure using the FF-inspired engine and publish that.  I think I could have done, but as I never did it's a moot issue.)


Anyway, if any of that makes sense, maybe (@ductape) try doing that.  I leave branching-plotline-progression organisation up to you, as well as what features you need to implement.  Importing (or drawing from scratch, having some form of descriptor information) images and displaying them is something you can do or not.  It barely gets more complicated to have a sprite-based worldview of one kind or another, at all times.  All the rest (as well as most of what I've already mentioned) is just data.


[1] Only to "buy the cloak" if one had enough credits in the appropriate part of the stat-tracking data-holder.  Only able to "shoot the robot from afar" if one possessed the suitable weapon".  Initiate combat if there's something to initiate combat with.  Sometimes there were pages that said something like "if you have previously read a spellbook, go to the page that is the number in its title, plus 50", so as to trivially hide the solution (especially if there had been two spellbooks, one for an advantage, one for a disadvantage), but that sort of thing got implemented automatically as well.

[2] e.g. combat, in a further sub-loop that let you follow the battle and choose to 'use' any special equipment that you might have...

[3] Magic points, for example, if the first one was all about giant robots instead, but I'd leave the possibility of "Vehicle stats", or even eventually make it open-ended so that the data-input could also define arbitrary stats that needed remembering, too...
« Last Edit: October 18, 2012, 05:02:25 am by Starver »
Logged

ductape

  • Bay Watcher
  • MAD BOMBER
    • View Profile
    • Alchemy WebDev
Re: Programming Help Thread (For Dummies)
« Reply #890 on: October 18, 2012, 12:40:21 am »

The code would be really simple if you ask me. The hardest part, for me, would be the art work and making it all look nice.

Never played King Of Dragon Pass (not, that I recall, even heard of it... which probably says something about me).

But.  Back in the day (decades ago) I put an entire Fighting Fantasy book onto a microcomputer (without its pictures).  Coding for that was fairly simple, and most of the hard work was the data entry.

Each story text already had a number assigned to it, and (unless a win/lose condition page) had one or more numbers that you could then follow onwards to (explicitly or otherwise).  So I stored each 'page' number, the text it gives and the choices (if any), plus details about any special conditions[1], and I suppose I could have stored details of how to draw pictures.  The basic code (in fact, it was BASIC code!) just repeatedly assessed the 'current page', output what it needed to, dealt with any calculations that were necessary[2].  Changing it to reflect a second FF book's "plotline" would have been fairly easy (just tedious) in getting the information input and perhaps an enhancement of the basic engine to add something that the second book needed that I hadn't needed for the first[3].

Which is basically the approach that I suspect a lot of branching-plot games-engines follow, like SCUMM/ScummVM.

These days, I'd probably even just re-do it in HTML, with a little bit of scripting (either server-side or client-side, according to taste) where necessary, but this was a pre-web era I was talking about.  (Also prior to my being on the Internet, and didn't have too many people with whom I could share the save-tapes of my creations, so it was for my fun and enjoyment alone (mostly, in the creating, rather than the playing), and no real chance that I'd be sued for copyright over the content I'd 'stolen', from the book that I owned but was still not allowed to "duplicate electronically or physically", or whatever the phrase was.  The question arises whether I could have developed my own adventure using the FF-inspired engine and publish that.  I think I could have done, but as I never did it's a moot issue.)


Anyway, if any of that makes sense, maybe (@ductape) try doing that.  I leave branching-plotline-progression organisation up to you, as well as what features you need to implement.  Importing (or drawing from scratch, having some form of descriptor information) images and displaying them is something you can do or not.  It barely gets more complicated to have a sprite-based worldview of one kind or another, at all times.  All the rest (as well as most of what I've already mentioned) is just data.


[1] Only to "buy the cloak" if one had enough credits in the appropriate part of the stat-tracking data-holder.  Only able to "shoot the robot from afar" if one possessed the suitable weapon".  Initiate combat if there's something to initiate combat with.  Sometimes there were pages that said something like "if you have previously read a spellbook, go to the page that is the number in its title, plus 50", so as to trivially hide the solution (especially if there had been two spellbooks, one for an advantage, one for a disadvantage), but that sort of thing got implemented automatically as well.

[2] e.g. combat, in a further sub-loop that let you follow the battle and choose to 'use' any special equipment that you might have...

[3] Magic points, for example, if the first one was all about giant robots instead, but I'd leave the possibility of "Vehicle stats", or even eventually make it open-ended so that the data-input could also define arbitrary stats that needed remembering, too...
[/quote]

I actually didnt write that which are quoting there.

Also, KoDP is not a branching storyline game, but thanks for taking the time :)
Logged
I got nothing

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #891 on: October 18, 2012, 04:59:41 am »

[snip confusion]

I'd got the [quote][/quote] tags wrong in my own message, during editing, which also means that in your latest message my own text dropped out of the quote-nesting and into 'your' bit.  (I'll edit my message, accordingly, but yours will still look as long and as wordy as mine was, unfortunately.  Because it is mine, almost entirely. ;) )

And I thought I'd read as such (that it was a branching storyline game[1]).  Maybe I was answering a different question to the one I thought I was.

Anyway, confusions sorted hopefully.


[1] edit to add: Thought it was this due to...
...a game similar to King of Dragon Pass. I mean, its mostly a choose your own adventure game...
...but I obviously misunderstood the context.
« Last Edit: October 18, 2012, 05:06:03 am by Starver »
Logged

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Programming Help Thread (For Dummies)
« Reply #892 on: November 04, 2012, 01:04:00 pm »

I cannot figure out how to read mp3 information in C#. All I need to do is read the artist, title, and album from an mp3, but it does not work. I have tried downloading a few libraries, but the only one I've found that does anything useful can only read some of my mp3s. (Semi-useful one)

In case it's relevant, I'm working in Unity. Thanks in advance for the help.
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Programming Help Thread (For Dummies)
« Reply #893 on: November 04, 2012, 01:43:01 pm »

So you want to read the metadata?

TagSharpLib is the one I usually see thrown around for ID3v1 and ID3v2 (and it's open source). Worst case, I guess you could find the specifications at http://id3.org/ and roll your own.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #894 on: November 07, 2012, 07:49:06 pm »

I'm trying to write a php script that will open a text file and increase the value of it by one (it's my attempt at making a simple polling system).

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Redirecting...</title>

<script type="text/javascript">
function createCookie () {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() + 1814400000);
var expire = expireDate.toGMTString();
document.cookie = 'a=1; expires=' + expire + "; path=/";
window.location = "index.html";
}
</script>

<?php
$file 
fopen("polls/" $_GET['option'] + ".txt""r+");
$data fread($file,filesize("polls/" $_GET['option'] . ".txt"));
$data $data 1;
?>

</head>

<body onload="createCookie()">
<?php
$file 
fopen("polls/" $_GET['option'] . ".txt""w+");
fwrite($file$data);
fclose($file);
header('Content-type: text/txt; Content-Disposition: attachment; filename="posts/' $_GET['option'] . '.txt"');
header('Location:index.html');
readfile("polls/" $_GET['option'] . ".txt");
?>

</body>
</html>

I know a chunk of it is working correctly, because the file opened gets changed to 1 when an option is selected (the only value passed to this page is a number, 1 to 6, with the name 'option'); however, it doesn't increase properly after the first increment. Does anybody have an idea what I might be messing up on? I've checked everything I could think of.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #895 on: November 07, 2012, 10:04:16 pm »

Because you are only setting it to one, change the line to 'document.cookie = 'a=3; expires=' + expire + "; path=/";' and you will find that the first time you run it, it sets it to three and then doesn't change.
You need to read the cookie first, increment it, then set it again as the new value.

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #896 on: November 07, 2012, 10:19:39 pm »

The cookie doesn't actually do anything other than mark computers that have already voted in the poll. "polls/" . $_GET['option'] + ".txt" (which works out to "polls/1.txt", "polls/2.txt", and so on) is the file being edited and having the value saved in.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #897 on: November 08, 2012, 03:42:00 am »

Perhaps it is reading '1' instead of 1, therefore trying to add 1 to a string? You could try
Code: [Select]
$data = intval(fread($file,filesize("polls/" . $_GET['option'] . ".txt")));
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #898 on: November 08, 2012, 07:02:51 am »

In C++:

I have a dilemma. I created a function

void assign_to_vector(vector<int> &vect, int par1 = 0, int par2 = 0, int par3 = 0, int par4 = 0, int par5 = 0, int par6 = 0, int par7 = 0) { /*implementation*/ }

in a header file. It then throws up the linkage error LNK2005: "void __cdecl assign_to_vector(class std::vector<int,class std::allocator<int> > &,int,int,int,int,int,int,int)" (?assign_to_vector@@YAXAAV?$vector@HV?$allocator@H@std@@@std@@HHHHHHH@Z) already defined in Engine.obj four times. However, if I then put it in the cpp file, it throws the error error C3861: 'assign_to_vector': identifier not found. It seems functions with default arguments always need to be defined with their declaration, while putting functions in header files causes linkage errors.

What the function does is take up to 7 int parameters and handle push_back() 'ing them, because I was too lazy to do them one by one/didn't feel like writing that code every single time I had to do that. What should I do?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #899 on: November 08, 2012, 07:10:31 am »

Put the implementation in the cpp, and the default-value in the definition (.h), and not in the implementation.

Code: [Select]
.h:

void assign_to_vector(vector<int> &vect, int par1 = 0, int par2 = 0, int par3 = 0, int par4 = 0, int par5 = 0, int par6 = 0, int par7 = 0);

.cpp:

void className::assign_to_vector(vector<int> &vect, int par1, int par2, int par3, int par4, int par5, int par6, int par7){ //implement that shit }

Question though, as you probably skip pushing back zeroes, what would happen if you actually want to push_back a value of 0? ;)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))
Pages: 1 ... 58 59 [60] 61 62 ... 91