Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 41 42 [43] 44 45 ... 91

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

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #630 on: June 01, 2012, 03:57:04 am »

The program is supposed to use a set of user commands to check whether the web aplication is running correctly. We want non programmers to be able to change the steps. An example of one of the commands would be like :

Something like lua might be your best bet here although I'm not a big fan of the language myself. If you do end up making your own I suggest you test it on a lot of non-devs as what programmers think seems simple tends not to be for those who don't thrive in code.

To be honest some kind of GUI to build the commands might be better, or maybe something like google-blocky which is a cross between the two.
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

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #631 on: June 01, 2012, 03:30:26 pm »

I've used arrays before; I actually changed Item to be an array while I was trying to figure out why it wasn't working here. That said, it honestly didn't seem to change anything - I literally just did a "find-replace" for "Item#" with "Item[#]" (making sure to add in a Item[0], of course). Is there any real benefit for having it in an array?

Mostly the reason is that it's easier to change later and generally neater, but there are some functional differences. For instance, if you ever need to do something to all the items in your item stack, (like unequip everything or something) you can just iterate through them all with a for loop. Or a foreach loop, if you're feeling especially hard boiled at the time. Also, you can pass the whole item pile as a function parameter.

As for comparing strings with "==", it's still a bad idea even if it sometimes works. Eventually you're going to use it on a string that is not constant, and then your program will bug out and you'll spend like half an hour trying to figure out why. And while I'm criticizing your string comparisons, you seem to have made a habit of passing strings as function parameters and then checking whether that string is the same as some other string. This is more a job for a boolean, and anyway, once the number of possible critters gets higher, you are going to have this huge, inefficient switch-case ladder and other programmers will point at you and call you names.

Using descriptive variable names often makes it harder to make stupid mistakes, and the guy who taught my sole college-level programming course drilled us into always writing Javadoc comments every time even when the code is really obvious, and I heartily recommend both. Don't listen to the "you need to study more before you can start coding" arguments, though. An overambitious project is the best way to learn anything. Worst-case scenario, you need to redo your code later, and that usually happens anyway, no matter how much one plans for the future. :P
« Last Edit: June 02, 2012, 03:02:13 pm by Soadreqm »
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Programming Help Thread (For Dummies)
« Reply #632 on: June 02, 2012, 09:54:32 am »

I am a big fan of writing documentation into my code. It's usually inside of methods and next to EVERYTHING :D I do it because I have the tendency to get side tracked into another project and then I come back a few weeks or months later and forget what my variables are supposed to do. All of the comments really cuts down on reestablishing my train of thought on the project.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #633 on: June 08, 2012, 06:37:04 pm »

Question about libtcod: what command would you use for printing a map? Would it just be...
Code: [Select]
TCODConsole::root->printCenteror is there a different way to print a map that is intended for that purpose?
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #634 on: June 20, 2012, 05:25:55 pm »

On a completely different topic, is there anyone here who could help me with getting a grip on HTML5? I'm trying to figure out how to make a simple game with JavaScript, but the map refuses to draw.

Code: [Select]
<!DOCTYPE html>
<html>
<body>

<canvas id="Map" width="400px" height="400px" style="border:1px solid #c3c3c3;">
</canvas>

<script type="text/javascript">

var arenaMaterial = [20][20];

var c=document.getElementById("Map");
var ctx=c.getContext("2d");

void initializeMap(); {
for (var xCount = 0; xCount < 19; xCount++) {
for (var yCount = 14; yCount < 19; yCount++) {
arenaMaterial [xCount][yCount] = 1;
}
}
for (var xCount = 0; xCount < 19; xCount++) {
for (var yCount = 0; yCount < 13; yCount++) {
arenaMaterial [xCount][yCount] = 0;
}
}
}

void printMap(); {
for (var xCount = 0; xCount < 19; xCount++) {
for (var yCount = 0; yCount < 19; yCount++) {
if (arenaMaterial == 0) {
ctx.fillStyle = "#EEEEEE";
ctx.fillRect(xCount*15,yCount*15,(xCount+1)*15,(yCount+1)*15);
}
if (arenaMaterial == 1) {
ctx.fillStyle = "#AAAAAA";
ctx.fillRect(xCount*15,yCount*15,(xCount+1)*15,(yCount+1)*15);
}
}
}
}

</script>

</body>
</html>

This is what I have so far. What it is supposed to do is create a blank white square and then fill it in with two different shades of grey. All it does currently is remain white. Does anyone recognize any stupid mistakes or syntax errors that I made? Or is it a failure to use a command properly that's screwing it up?
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #635 on: June 20, 2012, 06:09:14 pm »

In printMap(), I'm guessing its supposed to read:

Code: [Select]
if (arenaMaterial[xCount][yCount] == 0) {and
Code: [Select]
if (arenaMaterial[xCount][yCount] == 1) {
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Araph

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

Whoops, my bad. After fixing that, it still isn't working. For some strange reason, having
Code: [Select]
ctx.fillRect(0,0,100,100);before initializeMap() works, but placing that anywhere after or in the functions doesn't display a result.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #637 on: June 20, 2012, 07:17:30 pm »

I don't know the first thing about HTML5, I'd guess that CTX or something related to it needs to be initialized before you call initializeMap() and calling fillRect(int,int,int,int) auto-initializes it.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #638 on: June 20, 2012, 07:46:57 pm »

Code: [Select]
var c=document.getElementById("Map");
var ctx=c.getContext("2d");
Ctx is apparently a variable derived from another variable; I'm basing the HTML part of this project off of a tutorial, so I'm not entirely sure how this fits into the bigger picture (that is, I don't know why this variable is necessary).

'c' is storing the id of the canvas being drawn upon, though. I assume ctx is part of determining how the canvas is being drawn upon.
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Help Thread (For Dummies)
« Reply #639 on: June 20, 2012, 09:24:04 pm »

Javascript?

I might be doing this wrong, but pasting it into a plain text document, renaming it .html, loading it in Firefox, then bringing up the error console, I encountered a few problems.

It didn't recognise those as function definitions until the "void" was changed to "function", and the semicolons between that and the function body were removed. Then, of course, they weren't being called, so to get anything to happen, I added an extra call to each of them afterwards. It still had an error, though, with the array declaration, and googling about it brings up a completely different way to create a two dimensional array.

Then, finally, it would run.
Logged
Eh?
Eh!

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #640 on: June 20, 2012, 11:01:06 pm »

Thanks! I was basing the functions and array declarations off of C++, which was stupid of me. I wasn't aware that functions worked like that with JavaScript, and the way Dreamweaver marked the 'void' blue made it appear to be a valid command.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #641 on: June 21, 2012, 12:47:30 am »

Hello, a programming Dummy here! I've picked up C#, learned basic stuff about classes, namespaces, abstract classes and other stuff, also how to separate code in different files and how to make .dll and connect them to the code... So I wrote a few math programs using the System namespace from .NET, the most complex so far is an imitation of complex numbers and vectors using abstract classes (two different programs of course).

So, can anyone recommend me any good tutorial or a way to move from here? I want to learn how to write basic stuff like Snake or Tetris, but I only know the console output (Console.Write/Console.WriteLine), where should I check to learn to create a "visual output" window and work in it (just basic stuff, the maximum limit should be a roguelike :P).
« Last Edit: June 21, 2012, 12:53:55 am by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Whitefoxsniper

  • Bay Watcher
  • something meaningful.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #642 on: June 21, 2012, 01:20:16 am »

If your wanting to make games for C# XNA is good, sortof like the easy version of directX.

If your wanting to make applications your going to have to learn the windows API. Though I am a C++ and Java programmer and I have never used .net so maybe I don't know what I'm talking about.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #643 on: June 21, 2012, 04:11:23 am »

I want something really simple, like a text output, which is used to make basic text games. Basically a work with screen output or something like that. I don't want to go deep into existing libraries and I don't want ot use DirectX yet, just the basic stuff to understand how it works.

P.S. Maybe someone knows a simple tutorial how to draw a picture with symbols and refresh it (for a simple tile-based game, like a snake or a bomberman)? The ones I've found are very specific and they just give you all the code, while I would like to write it by myself following general instructions.
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #644 on: June 21, 2012, 04:37:24 am »

XNA. Seriously, it's the simplest C# drawing library there is.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.
Pages: 1 ... 41 42 [43] 44 45 ... 91