Slasher

Advice on general approaches or feasibility and discussions about game design

Slasher

Postby Skyrunner65 » Sun Nov 02, 2014 12:23 am

Hello,
As I may have said QUITE a bit of time ago, I was maybe going to make a game called "Slasher" in which you are the Alfred, a serial killer fully dressed in black. I am somewhat set on doing this (until I FINALLY get Windows for my computer), but I am just fifteen, so I will hit snags. I hope that the community can help me with any of said snags in order to make my game a reality.

Here, I will post two build versions: Broken and Stable.
Image
Stable
Broken
Last edited by Skyrunner65 on Mon Dec 29, 2014 9:38 pm, edited 7 times in total.
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher (Need So Much Help!)

Postby Skyrunner65 » Sun Nov 02, 2014 12:31 am

So, first errors :
Code: Select all
player.ino: In function 'void loop()':
player.ino:1:6: error: redefinition of 'void loop()'
SlasherBroken.ino:28:6: error: 'void loop()' previously defined here
player.ino:3:16: warning: statement has no effect [-Wunused-value]
player.ino:6:16: warning: statement has no effect [-Wunused-value]
player.ino:9:16: warning: statement has no effect [-Wunused-value]
player.ino:12:16: warning: statement has no effect [-Wunused-value]


Now I have an idea on what the last four are, but "playerx" and "playery" are already defined on the main .ino.

Honestly, this is just to get a basic grasp on moving a "character"(bitmap).
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher (Need So Much Help!)

Postby Myndale » Sun Nov 02, 2014 4:54 am

The error is because you have a function called "loop" in your main Slasher.ino file and another function also called "loop" in your player.ino file. Function names have to be unique, otherwise the compiler has no way of telling which one you're trying to call.

The last 4 issues are warnings rather than errors. Errors get generated when the compiler cannot turn your code into an executable, warnings get generated when the compiler can still make a working program from your code but it's detected that you're probably doing something you didn't actually intend to. That is in fact the case with your program because you have four statements that look like this:

Code: Select all
if (gb.buttons.pressed(BTN_UP)){
    playery - 5;
  }


The term "playery - 5" doesn't actually do anything. It calculates the value of playery - 5 but you haven't told it to store the result anywhere, so the compiler usually won't even bother doing the calculation in the first place. You can fix this warning by changing it to one of the following:

Code: Select all
    playery = playery - 5;
    // **OR***
    playery -= 5;
 


Both of these lines do exactly the same thing although you'll find most people typically prefer the second form.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Slasher

Postby Skyrunner65 » Mon Nov 03, 2014 12:11 am

So what should I do? I've tried naming "void loop" to "void buttons", and that doesn't work.
And yes, I have read the Arduino reference and there is only setup() and loop(), so should I put the second void loop() under the first, or make a variable that says if the player is in-game? I'll probably do the second one.
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher

Postby Jolly » Mon Nov 03, 2014 9:15 pm

Skyrunner65 wrote:So what should I do? I've tried naming "void loop" to "void buttons", and that doesn't work.


What doesn't work? The movement? If you named it buttons() then you need to call it in loop().

Skyrunner65 wrote: so should I put the second void loop() under the first


No, you can only have one "void loop()". All the other functions have to have different names, otherwise how should the program know which function has to be executed?

So you should do something like this:

Code: Select all
void buttons()
{
    // your player movement can go here
}

void setup()
{
    // all the gb stuff
}

void loop()
{
    buttons();
    // some more stuff
}


This is not a complete example, just to show you how your idea can work.
Jolly
 
Posts: 40
Joined: Fri Jul 25, 2014 9:07 pm
Location: Germany

Re: Slasher

Postby Skyrunner65 » Mon Nov 03, 2014 11:57 pm

Okay, I've updated the Broken version, and now my problem is that it is saying that for "player.ino" , it needs 6 times an lvalue at the left, but the lvalues are already there!
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher

Postby jonnection » Tue Nov 04, 2014 7:39 am

You are mixing two different things in your code.

If you do this:

int playerx;


... it is called "declaring a variable". This tells the compiler that there is a variable (<-variable means a memory storage that will change during the running of the game) called playerx and that playerx is of type signed (i.e. can be positive or negative) and is 16 bits in size.

However, if you do this:

#define playerx

... it is called a "macro" and it is a totally different thing. The macro is an instruction for the "preprocessor" to do some things to the code BEFORE the compiler begins compiling. It sounds complicated but let me give you an example:

Code: Select all

#define PLAYERMOVEMENT 5

int playerx = 0;
int playery = 0;

void play() {

if (gb.buttons.pressed(BTN_DOWN)){
      playery += PLAYERMOVEMENT;  // Pre-processor will replace PLAYERMOVEMENT with the value 5
    };

      if (gb.buttons.pressed(BTN_LEFT)){
      playerx -= PLAYERMOVEMENT; // Now I will automatically have the same value here, thanks to the  #define
    };
}


So: macro is a "shorthand" for doing something so that you do not have to change the same value everywhere in the code. But it is not the same thing as a "variable". You need to declare a variable (int something) in order to reserve a memory space for a value that you will use and change during the game.

So in your code when you have

#define playerx

What it actually does is tells the preprocessor is that "playerx" is a macro and all references to "playerx" should be REPLACED with a blank space

So the line of code

playerx += 5;

actually becomes this after the preprocessor has done its job:

+=5;

After the preprocessor, the compiler starts its job, looks at that code and is complaining that there is no "lvalue" (left hand value) in the equation to add the 5 to.
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Slasher

Postby Skyrunner65 » Tue Nov 04, 2014 7:09 pm

Thank you so much Jonnection, now I have controls down.
After this post, I'll update the Stable Release (even though it is only selecting story and then you can manipulate Alfred).
I'm going to make Options next, with (maybe) Frames per Second, Volume in 25 percent increments, and the battery will be shown. Then (hopefully) I can make a test overworld with signs (potentially an enemy and jump boosts[speaking of that, need to make animation too]).
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher

Postby Skyrunner65 » Tue Nov 04, 2014 8:13 pm

Since I'm off today due to elections, I'd thought I would make the options, which is embedded into the main file. However I've ran into problems while compiling:
Code: Select all
SlasherBroken.ino:4:15: error: expected initializer before numeric constant
SlasherBroken.ino:34:15: error: expected initializer before numeric constant


I don't know what the problem is, so i'm updating the Broken link.
Also, I know there aren't any complaints yet on how much I'm asking for help, but I have messed with some Python before ever knowing about the Gamebuino, so that's really my only experience.
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: Slasher

Postby jonnection » Wed Nov 05, 2014 12:02 am

The error is on the last line of this code. All lines of code need to have a semicolon (;) to terminate them.

The pre-processor / compiler goes line by line. If something fails at line 45, the mistake is usually there or the lines directly before.

Code: Select all
void setup(){
  gb.begin();
  gb.display.setFont(font5x7);
  gb.titleScreen(F("      Slasher"), logo);
  gb.battery.show = false;
  gb.sound.setVolume(100)
}
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Next

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 8 guests

cron