Jump to content


perludus

Member Since 12 Jun 2009
Offline Last Active Aug 08 2011 04:21 AM

Posts I've Made

In Topic: [GMPHP] Write a GameMaker variable

13 April 2011 - 03:12 PM

There are a lot of things that could be going wrong here and unfortunately it's hard to tell what.  My bet is that you PHP code is failing.  You need to make 100% certain your PHP is running without error before you proceed further.

You need to check if you are getting errors back from the database queries.  You're not checking for any errors at all and just assuming the query happens without issue.  Also, you're using the variable $bdd which I assume is set from a mysql_connect() call, but we don't see how it's created to make your initial connection to the database.  Are you sure it's actually set and that you actually connected in the first place?  

Definitely check out the php MySQL manual section at http://www.php.net/m.../book.mysql.php and look at the error checking methods.  Specifically, you should be calling mysql_error after EVERY database call.  If the returned value is blank, then there wasn't an error.  If a string of some kind is returned, then you had an error (and the error message is in the string).

See http://www.php.net/m...mysql-error.php for mysql_error documentation.

Here is a bit of code that shows a complete open, database select, query and close - the basics you'll need for any database use.

<?php
// --- Connect to the database server
$db = mysql_connect("localhost:3306", "username", "password");
if (!$db) {
    die ("COULD NOT CONNECT TO DATABASE:  " . mysql_error());
}

// --- Select the database to use
if (!mysql_select_db("my_database", $db)) {
   die ("COULD NOT SELECT DATABASE:  " . mysql_error());
}

// --- Do a query
$sql = "SELECT * from some_table";
$result = mysql_query($sql, $db);
if (!$result) {
  die ("QUERY FAILED:  " . mysql_error());
}

// ----------------------------------------------------------------
// --- Your code goes here that does something with the results of the above query
// ----------------------------------------------------------------

// --- Close the connection
mysql_close($db);
?>

In Topic: Top view cannonball effect

12 April 2011 - 02:36 PM

Hello.
I have a TD game, where i want mortar pit to fire cannon ball. It should get bigger on some way and then smaller again to make this bow effect. But i dunno how to do it. The game is top view. Can u help me plz?


Use the sin function to create a value that varies from 0 at the start, 1 at the peak of the rise and 0 at the end.   Then use that value (with an offset) as the scale for the cannon ball.  

Here is some code that would show how the scale is calculated.  Assume the ball starts at x=0 and goes all the way to x=500 in this case.  The scale will vary from 0.5 at the start and end of the "lob", and be at a value of 1.5 at the middle.  

max_x = 500;
x = 0;
while (x<max_x) {
  scale = sin((x/max_x) * pi) + 0.5;
  x = x + 1;
}

Obviously you wouldn't use the code like this straight up, but rather pull out elements of the inner loop and use them in a step event for example.

In Topic: Duplicating some AGS room functions in GM

11 April 2011 - 05:57 PM

This looks great! Thanks!

I DL'ed the PC trial version and loaded up your example on another machine to take a look at the code.

In Topic: Duplicating some AGS room functions in GM

11 April 2011 - 05:45 PM

Pixela? Bitmap reading? Oh my, don't do that.
There is a much simplier way. Here, [Example].
Question: May I add this example as it is now (with your background and sprite) to existing collection of examples on my site?


Hmm.  I'm running on a Mac (latest, pro version) and it won't load the example file as it was created with a "newer version".  While I see about getting GM on a PC can you give an overview?  Also feel free to copy the images and host on your website.  

You've got a nice collection of examples there by the way (which also don't load on GM Pro on a Mac).  *glares at YoYo and wonders when the Mac version will reach 8.x*

In Topic: A* path finding

11 April 2011 - 04:27 PM

Zhall, I just have gotten into pathing so I'll give you a bit of info on what I've found.

First, check out the mp_grid functions. You'll want to create an mp_grid that maps out where players can go and can't go, then with that map you can ask it to calculate paths between two points via A* pathing.

Second, you can probably keep the object system you're using, and create an mp_grid based on your objects. Here's the code I used in my room create code...

global.test_grid = mp_grid_create(0, 0, 128, 96, 8, 8);
x=0;
while (x<128) {
  y=0;
  while (y<96) {
    mp_grid_add_cell(global.test_grid, x, y);
    node_id = instance_position(x*8+4, y*8+4, node_16);
    object_set_visible(node_id,false);
    if (node_id != noone) {
      mp_grid_clear_cell (global.test_grid, x, y);
    }
    y = y + 1;
  }
  x = x + 1;
} 

In this case, I'm creating a grid with an 8 pixel resolution by searching for an object called "node_16" that I place in every location where the player can walk.

In my case I have a player object, and I want the player to walk to wherever the mouse clicks. Here's the code that handles creating the path and starting it going. target_x and target_y are the coordinates of the mouse click (where you want the player to go). Also "grid_path" is a path I created in the GM editor.

mp_grid_path(global.test_grid, grid_path, self.x, self.y, target_x, target_y, true);

path_start(grid_path,5,0,true);