Autor Tema: Accessing public variables  (Leído 10239 veces)

Jongf7

  • Newbie
  • *
  • Mensajes: 19
  • Karma: 1
Accessing public variables
« en: Mayo 14, 2011, 10:07:12 am »
Hello,

I am trying to rewrite an old DIV game of mine for windows in BennuGD.
It was a simple game in witch rocks fell from the sky and you had to shoot them to survive.

This time I would like to ad some extra’s and one of them is keeping me problems at the moment.

The rocks don’t fall straight down, but do this in a random angle, and the also have random speeds.
This means the rocks can hit each other.
In the original game the rocks would fly behind or in front of each other without hitting.

I would like them to hit and change course on hit this time around..

For this I made the variables that give the rocks there x and y speeds public.

Now I try to get the x and y speed of the colliding rock on collision to do some math on how to alter the rocks speed, this is where it goes wrong.

Código: [Seleccionar]
if (colliding_rock=collision(type rock)) x_speed=colliding_rock.x_speed\2; end
If I use this code I get the error “unknown identifier ( token error: “x_speed” ).


Can you see what I am doing wrong here?


darío

  • Sr. Member
  • ****
  • Mensajes: 458
  • Karma: 48
Re: Accessing public variables
« Respuesta #1 en: Mayo 14, 2011, 10:57:54 am »
Hi,

when you want to use public variables you need to "declare the process" so as the program knows which public variables has each process.  Take a look at this page on the BennuGD wiki: http://wiki.bennugd.org/index.php?title=Declare

Hope it helps!

My sites:
Smart Fpg Editor - Painless FPG Edition for Bennu and PixTudio
fenixlib - .NET support for manipulating PixTudio, Bennu and Div graphic formats

Jongf7

  • Newbie
  • *
  • Mensajes: 19
  • Karma: 1
Re: Accessing public variables
« Respuesta #2 en: Mayo 14, 2011, 11:39:32 am »
Hi,

I forgot to mention but I did declare the process and its public variables.
Could the problem be that I want to get variables from a process of the same type?

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12884
  • Karma: 377
Re: Accessing public variables
« Respuesta #3 en: Mayo 14, 2011, 03:25:44 pm »
how you declare colliding_rock ?
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

tmoney

  • Jr. Member
  • **
  • Mensajes: 64
  • Karma: 9
Re: Accessing public variables
« Respuesta #4 en: Mayo 14, 2011, 07:27:10 pm »
make sure you declare colliding_rock as type rock

Código: [Seleccionar]
PRIVATE
  rock colliding_rock;  //this will give you type rock


Código: [Seleccionar]
PRIVATE
  colliding_rock;  //this will give you type int, and is probably causing your error

Jongf7

  • Newbie
  • *
  • Mensajes: 19
  • Karma: 1
Re: Accessing public variables
« Respuesta #5 en: Mayo 17, 2011, 03:27:14 pm »
I am sure I didn't declare rock the way you describe here (I did it the way you describe not to do it..).
I think I always declare everything as INT, I will read in to what other ways there are and what they do.


I had this part of the game on hold for the moment, but I will experiment with it again as soon as I have time. I will let you know if it solved the problem.

Thanks for now!

(also to the others who posted here)

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: Accessing public variables
« Respuesta #6 en: Mayo 17, 2011, 06:51:53 pm »
Maybe this page is of help: http://wiki.bennugd.org/index.php?title=Public_variables

The Beginner's Tutorial had more on this matter, but it was deleted for some reason.
-- Sandman

Jongf7

  • Newbie
  • *
  • Mensajes: 19
  • Karma: 1
Re: Accessing public variables
« Respuesta #7 en: Mayo 17, 2011, 09:31:23 pm »
Thanks, I think I will need to read into the different kind of data types for variables.


I have a new question now, I hope it is ok to ask it in this same threat.

The game is now coming along nicely and I would like to share it with some friends.
I used to copy the interpreter file and give it the same name as the .dbf file, this way you could start the game without using a command prompt. This doesn't seem to work anymore though.
How can I make an executable for my game now?

Edit:

I have it working now, I created a shortcut to the bgdi.exe and added ‘ gamename.dcb’ as parameter.
If there is a more elegant solution I am still interested.
« última modificación: Mayo 18, 2011, 06:07:34 am por Jongf7 »