Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 481 482 [483] 484 485 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 909269 times)

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7230 on: April 20, 2015, 05:25:29 pm »

...Got it. Had to use quotation marks instead of <>. didn't know I could do that. thanks, basic c++ programming class from college. thanks, stack overflow for teaching me stuff.

End result is #include "pdc34dllw/curses.h" which compiles and gets no errors.

EDIT: Nope, don't got it. Attempting to use the code specified in the tutorial that's juuust after including curses, the part that should work if I included it correctly, results in errors. Errors are all "undefined reference to x" where "x" is whatever is in each line of code below.

« Last Edit: April 20, 2015, 05:30:03 pm by Spehss _ »
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7231 on: April 20, 2015, 05:46:46 pm »

Did you configure your IDE's linker for the library?
Considering I have no idea what that means, probably not.

Googling has taught me how to do that. I have now done that. Hurray, getting somewhere.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Araph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7232 on: April 20, 2015, 06:13:11 pm »

If anybody out there wants to learn how to do the internet stuff in Unity, I recorded a couple videos on it. I can promise that I'm almost certainly not the worst teacher on YouTube, but no guarantees.

Networking Tutorials
JavaScript
Part 1
Part 2

C#
Part 1
Part 2
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7233 on: April 20, 2015, 06:29:33 pm »

I'm having a big problem with my code for my final project for Javascript. Its supposed to be a card counter that is supposed to count how many cards there are and spit out a total, if you're over or under a deck limit, and then spits out all the cards you have, the amount you have and it will tell you and prompt you again if you entered a card amount over the limit (in this case, its 3, though can be changed).

So far, if you enter a double, it enters a loop of "can't do that, enter another amount" even if its a valid amonut. Also, it seems to lose its shit if I enter 0...

On another note, if you somehow bypass the doubles, it seems to take the list and bash the numbers together for the total amonut instead of adding it together
(EX: "You have 03123131213232 cards" instead of "You have 27 cards")

Code: [Select]
<html>
<head>
<script type="text/javascript">
// Program Name: cardcounter.txt
// Purpose: Chris can't tell if he has enough cards in his deck. We're going to fix that
// Author: Spencer Durette & Benjamin Tofflemire
// Date last modified: 04/15/2015

//Declare Global Variables


var daCardTotal = 0; // Total Number of cards added
var daCard; // The card entered
var cardList = []; // The List of cards that will be displayed at the very end
var numbahOCards = []; // The list of the quantity of each card
var cardQty; // The number of cards entered
var index = 0; // The index used for the final loop in the program to display the total number of cards
var cardQtyCheck = false; // Checks if the card quantity is proper
var BR = "<br />";
var checkIndex = 0; // The index used in finding repeat cards
var cardDouble = false // Checks if there is a card double. This is counted as true if the card found is a double and will skip adding a new card
// as well as adding a new card quantity if this is true

//Set the Card Limit (40 for Yu-gi-oh, 60 for Magic: The Gathering)
var cardMax = 40;

//Declare the maximum number of cards per deck (This program doesn't count cards you can have an infinite number of,
//such as land cards and relentless rats in Magic: The Gathering)
var cardQtyMax = 3;

//Count the card total
var cardCount = function(daGrandTotal) {
if (daGrandTotal > cardMax){
alert("Please remove some cards. You are over the card limit");
document.write("Please remove some cards. You are over the card limit" + BR);
document.write("You have " + daCardTotal + " cards total")
} else if (daGrandTotal < cardMax) {
alert("Please add some more cards. You are under the card limit");
document.write("Please add some more cards. You are under the card limit" + BR);
document.write("You have " + daCardTotal + " cards total")
} else {
alert("You have exactly "+cardMax+" cards in your deck. You have the exact number of cards needed" + BR);
document.write("You have exactly "+cardMax+" cards in your deck. You have the exact number of cards needed" + BR);
document.write("You have " + daCardTotal + " cards total")
}
}

var cardRepeat = function(card) {
//Check if the card added has already been added to the list
while (checkIndex < cardList.length){
if (cardList[checkIndex] == card){
cardDouble = true;
cardQty = prompt("The card you have has already been added. Please enter the added amount (You have " + numbahOCards[checkIndex] + " already added)");
cardQty = parseInt(cardQty);
while (cardDouble == true) {
if ((cardQty + numbahOCards[checkIndex]) >= cardQtyMax){
cardQty = prompt("The card amount entered is invalid. Please enter a valid amount (You have " + numbahOCards[checkIndex] + " added already)");
cardQty = parseInt(cardQty);
} else if ((cardQty + numbahOCards[checkIndex]) < cardQtyMax) {
numbahOCards[checkIndex] = numbahOCards[checkIndex]+cardQty;
break;
}
}
break;
}
//Increment the card index for the card list
checkIndex += 1;
}
//Once the check for doubles is finished, reset the card index for the next card
checkIndex = 0;
}

</script>
</head>
<body>
<script type="text/javascript">
//Welcome the user
alert("Welcome to the card counter program!");

//Run the program

//Prompt the User to enter the first card
daCard = prompt("Please enter the first card","");

//Enter the loop that will have the user consistently enter cards until they entered all of the cards needed
while (daCard != "-1") {
//If the user enters -1, the program stops counting cards
if (daCard == "-1") {
break
} else {
//Check if the card is a double
cardRepeat(daCard);

//Run the regular card adding if the card is not a double
if (cardDouble == false) {
//Add the card to the list of cards by name
cardList[cardList.length] = daCard;;
//Prompt the user for how many cards there are
cardQty = prompt("How many "+daCard+"s are there to add?");

//Check if the card quantity is a valid amount (defined by the variables above)
while (cardQtyCheck == false){
if (cardQty > cardQtyMax) {
//Tell the user that the amount of cards they added is invalid if they entered more then the maximum of allowed cards
alert("You cannot have that many cards in a deck, please enter a valid amount");
cardQty = prompt("How many "+daCard+"s are there to add?");
cardQty = parseInt(cardQty);
} else {
cardQtyCheck = true;
//Add the card quantity if the card total is right
numbahOCards[numbahOCards.length] = cardQty;
cardQty = parseInt(cardQty);
}
}
}
//Add to the grand total of cards that will be displayed at the end
daCardTotal = daCardTotal + cardQty;
//Loop the prompts, this time adding the option to exit with -1
daCard = prompt("Please enter the next card (-1 to exit)","-1");
//Changes the check so the next quantity of cards is checked
cardQtyCheck = false;
}
}

//Count the grand total of cards and checks if the cards are over or under the total amount of cards allowed
cardCount(daCardTotal);

//Displays every card with its respectable number, stopping when the list ends
            while (index < (numbahOCards.length)){
if (numbahOCards[index] == "" || cardList[index] == "") {
break;
}
document.write(BR + cardList[index]+" x"+ numbahOCards[index] + BR);
index += 1
            }
</script>
</html>

I know its hard to look at, but please bear with me on this. I'll also take any recommendations to make it look... Cleaner? (is that how I would describe it?). I also would like it if someone can explain to me whats going on...

Kinda got left in the dust, so bumping my post because I'm still bashing my head off the keyboard trying to figure out whats making my program flip tables when I enter 0...
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7234 on: April 20, 2015, 11:28:22 pm »

Did you configure your IDE's linker for the library?
Considering I have no idea what that means, probably not.

Googling has taught me how to do that. I have now done that. Hurray, getting somewhere.

an include file gives the definitions of the functions and stuff so that your program passes the compile stage. But most libraries don't include the entire functions inside the .h file. The .h file just specifies function names and what data types they take as parameters. In the first compilation pass, the compiler puts in "dummy" calls to all functions that are in another module (i.e which have their body in a different .cpp file). The final "linker" stage works out the actual memory address for each function, and replaces the dummy function calls in each module with a real memory address.

Since there are different stages which are checking for different things, you need to keep and eye on what stage you get error messages. If it's during the stage when .cpp files are being processed, then it's an error in your code somewhere. If it gets to the linker stage, then it's often not a syntax error, but there was a function call where the body of the function wasn't defined in any module which has been included in the project.

Modules usually have a separate .cpp file, which also needs to be part of your project, or they have a pre-compiled .cpp file distributed as "thingname.lib" that has all the actual function bodies in it. You need to tell your IDE's linker that the lib file is part of the project otherwise you get "undefined" errors when the compiler does the final pass to stitch all the code together. In Visual C++ you can open your Properties for the project, and add your new lib to the list of libs. I think it's under a "Linker" section.
« Last Edit: April 20, 2015, 11:31:59 pm by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7235 on: April 21, 2015, 11:09:52 am »

For PDcurses, I *think* you also have to compile with a special option, -pdcurses or something like that. I don't remember exactly.
It's ass to get working, but that seems to be the case for everything related to using external libs.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7236 on: April 21, 2015, 01:13:51 pm »

@miauw62 - I didn't have any trouble getting it working at all, just link the .h file where it's need and put the .lib with the existing list of lib files to include in the linker. It took me a couple of minutes getting it set up. Note, this is from the pre-compiled one I linked. It is hard to work out how to compile it yourself, so I just use the compiled DLL version.

@highmax, you're not actually changing the value of "cardDouble" back to false in the inner loop of the "cardRepeat" function, hence it never breaks out of the loop. This also causes issues when the next card is picked, since cardDouble is left as TRUE all the time. One good rule of thumb is to always set cardDouble to false at the start of each cardRepeat call. This will prevent previous values of cardDouble from wrongly affecting the result. I didn't get the incorrect addition problem though and couldn't replicate the problem with entering 0. When does that happen? I think it's probably related to not reseting cardDouble when needed.
« Last Edit: April 21, 2015, 01:30:46 pm by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7237 on: April 21, 2015, 01:31:56 pm »

It's really confusing for a beginner though, since you have no fucking clue where you have to add references to the library.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7238 on: April 21, 2015, 01:33:32 pm »

It's pretty much the same for every library though, so it's just something you have to learn once, and no harder than any other language feature.

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #7239 on: April 21, 2015, 02:16:33 pm »

Anyone familiar with javascripts node.js and Browserify functionality? I'm trying to access node.js's buffer class, and in order to do that I'm trying to bundle it with my code with browserify. Of course, now I'm getting "ReferenceError: JSAgoraLib is not defined" when it slearly is defined in this file: http://angle.webfactional.com/JAgoraHTTPServer/js/libs/bundle.js. Anyone have any idea what my problem is?
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7240 on: April 23, 2015, 01:37:22 pm »

Want to make sure I'm understanding this right. Say I have an array full of '#' chars.

Spoiler: array 1 (click to show/hide)

Spoiler: array 2 (click to show/hide)

So that to access contents, arrayOne would be arrayOne[X] which would be slot X, or coordinate (X,0) on the graph, where arrayTwo would be arrayTwo[X][Y] which would be the slot at coordinate (X,Y) on the graph.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7241 on: April 23, 2015, 01:40:05 pm »

In C++, your array would be numbered from 0 to 9, not from 1 to 10. This is true for most programming languages.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7242 on: April 23, 2015, 01:41:28 pm »

In C++, your array would be numbered from 0 to 9, not from 1 to 10. This is true for most programming languages.
Right. Forgot about that. This was just hypothetical.

So other than that, I'm understanding this right?
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7243 on: April 23, 2015, 01:48:20 pm »

Think so, yeah. I wouldn't recommend actually using arrays in C++, though, and especially 2D arrays. imo vectors are much easier to use.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7244 on: April 23, 2015, 01:54:58 pm »

Think so, yeah. I wouldn't recommend actually using arrays in C++, though, and especially 2D arrays. imo vectors are much easier to use.
brb lrning vectors
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.
Pages: 1 ... 481 482 [483] 484 485 ... 796