Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Egmundo Huevoz

#1
Hi everyone! After a 3+ year abscence, I decided to come back and make yet another game! Glad to see the forums still alive.

I have a work in progress game in which I, with a loooooot of help (like 95%), managed to make a shop GUI to buy and sell items, which can get grouped by quantity. For example, 6 donuts, you click once, and buy 1 donut, so the shopkeeper has 5 and you have 1. That's working fine. The problem is, if I have 2 or more donuts, my inventory only shows one (I disabled "group inventory items"). Somebody (I think it was Khris) helped me to show the inventory item quantity in said GUI shop, but I couldn't translate the code to work in the regular inventory. And now I mostly forgot everything about everything, so I'm trying to reverse engineer things. But it seems I couldn't do it even at my best, according to the last answer I made in the original post.

The original post: https://www.adventuregamestudio.co.uk/forums/index.php?topic=55564.msg636577866#msg636577866

The part of the shop's code which (I think) displays item quantities:

Code: ags

void DrawQuantities(DrawingSurface* ds, InvWindow* iw) {
  InventoryItem* ii;
  Character* c;
  int i = iw.TopItem, iq, w, h;
  String s;
  for (int y = iw.Y; y < iw.Y + iw.Height; y += iw.ItemHeight) {
    for (int x = iw.X; x < iw.X + iw.Width; x += iw.ItemWidth) {
      ii = iw.ItemAtIndex[i];
      if (ii != null) {
        c = iw.CharacterToUse;
        if (c == null) c = player;
        iq = c.InventoryQuantity[ii.ID]; 
        if (iq > 1) {
          s = String.Format("x%d", iq);
          w = GetTextWidth(s, shopFont);
          h = GetTextHeight(s, shopFont, 1000);
          ds.DrawingColor = 0;
          ds.DrawString(x + iw.ItemWidth - w, y + iw.ItemHeight - h, shopOutlineFont, s);
          ds.DrawingColor = 31;
          ds.DrawString(x + iw.ItemWidth - w, y + iw.ItemHeight - h, shopFont, s);
        }
      }
      i++;
    }
  }
}



void ShowQuantities() {
  if (quantities == null) quantities = DynamicSprite.Create(gShop.Width, gShop.Height, true);
  DrawingSurface* ds = quantities.GetDrawingSurface();
  ds.Clear(COLOR_TRANSPARENT);
  btnShopQuantities.Height = 1;
  DrawQuantities(ds, invShopPlayer);
  DrawQuantities(ds, invShopMerchant);
  btnShopQuantities.Height = gShop.Height;
  ds.Release();
  btnShopQuantities.NormalGraphic = quantities.Graphic;
}



Any help in how to do this would be greatly appreciated!
#2
EDIT: lol, it seems I repeated the answer posted above by CW, disregard my comment (laugh)

Maybe you could make a "translation"?
You see, when translating, AGS creates a file with all the text from your game, so it can be quickly translated. As you could translate fron English to Spanish, for example, you could also use that file to "translate" from "misspelled English" to "correctly spelled English" (laugh) You can open that file with any text editor.
I actually thought about using the translate feature for something like this. To make a game where the character swears, and in the menu, you can turn swearings off (replacing those words with symbols like â,¬@#~ or whatever) by using a translated file.

I don't know if it's feasible, I think it is, but somebody correct me if I'm wrong.
#3
Quote from: bx83 on Mon 12/02/2018 01:03:26
Buckethead: I've never heard of this before, does it work for anything always just by including the text? Are there any other @ variables in th game?
Yes, it works for everything, provided it has a name (for instance, if you create an object and don't name it, nothing will show).
If you search "@overhotspot@" in the manual, it will direct you to an entry called "editing the GUIs". There, under "interface text", is a list of other commands you can put into a label.

Quote from: AGS
@GAMENAME@    The game's name, specified on the Game Settings pane
@OVERHOTSPOT@ Name of the hotspot which the cursor is over
@SCORE@       The player's current score
@SCORETEXT@   The text "Score: X of XX" with the relevant numbers filled in.
@TOTALSCORE@  The maximum possible score, specified on the Game Settings pane

Anyway, you can show lots of information in labels, but you'll need to know the basics of scripting. If you're interested, I can explain further.
#4
Hey, man. A couple of months ago, I was in your shoes. But the good people on this forums helped so much, that now I understand a lot of things (still a noob, but not so much anymore :-D ). Sooo I'm confortable enough to try and help you out.
What you want is simple enough, I think. You want a stress/sanity level. Okay, your character becomes crazier and crazier when he does some things, right? We can just track this with a variable. If you're gonna have more "stats" to your character/s (like, I don't know, luck, strength, or something you'd see in an RPG), you probably should use structs, arrays, and/or extender functions but, for now, if you don't need this, I'll skip them. If you DO need them, let me know and I'll explani that.
I'm gonna assume you use stress and sanity as 2 extremes of the same variable. First you create global variable, named "stress", or whatever you want. We'll leave the default value to 0. Then, whenever your character does something that makes him more or less stressful/sane/crazy you just do this:

Code: ags

//you can use these anywhere in your code.
stress ++; //this increases stress by 1
stress --; //this decreases stress by 1
stress += 10 //this increases stress by 10, you can replace that number with any number you want.
stress -= 10 //the same but decreasing stress


Also you'll want to set your stress limits. In my example I made them 0 and 100, but you can do whatever you want.

Code: ags

//in repeatedly_execute
if (stress<0){ //so you can't have negative stress.
    stress = 0;
}
if (stress>100){
    stress = 100;
    //or lose the game, die, or whatever you want.
}


Then, to change events depending on how much stress your character has, do something like:
Code: ags

cBoss.say ("You're fired.");
if (stress < 25){
player.say("It's okay, I'll find another job soon enough.");
}
else if (stress < 50){
player.say("Oh yeah? Up yours, old man!");
}
else{
Display ("You grab your chair and proceed to bludgeon your boss to death.");
}



You'll want to know how much stress your character has. You can do this in several ways:

1) By displaying it in certain circumstances (by clicking a button, for instance):
Code: ags

Display ("Your character has %d amount of stress!", stress); //%d displays the value of an int, in this case stress.


2) By displaying it on a GUI's label. Create a GUI for displaying you stress, and there create a label called "lblStress".
Code: ags

//in repeatedly_execute
String StressDisplay=String.Format("Stress: %d", stress);
lblStress.Text=StressDisplay;


3) Like you wanted, by using a "stress bar". I think you should combine this with method 2. I've made this a long time ago, only once, so I don't know if it's the easier method, but it works. Make a sprite of a rectangle, and make it 100 px wide (that would be our max, but you can make it whatever you want). Then make a button on your stress GUI, called btnStressBar. Use your rectangle sprite as your button's sprite. In the button's properties, make "clip image" true.
Code: ags

//in repeatedly_execute
btnStressBar.Width=stress;



If something doesn't work, you don't understand something, or need anything else, don't hesitate to ask.



#5
Thanks, CW! That sounds like it should work, I'll be testing it as soon as I finish with some other stuff. As for the iso guide, I've been reading it a lot, but I still can't figure out how to translate it to AGS. Luckily, I'm getting help via PM, so no problems there. Even if I can't figure it out eventually, this grid is not essential for my game. Cheers!
#6
CW: I thought of that, But if I set the object.Clickable to false, even for a frame, it makes that wall visible again (because my function makes the wall transparent when it's colliding with my player), even if it's for a frame. Visually, it's unpleasant. At least, if I understood what you want me to do correctly. No worries, I'm sure I'm gonna figure this out on my own eventually, it's not a real problem. Even if I fail, I can always make the 2 walls to become transparent together, even though it's not my ideal solution.

What's reaaaally puzzling me now is how to make a coordinate system for an iso grid. I read a few guides online (not for AGS, but in general). It seems I need to convert cartesian coordinates into isometric ones using a couple formulas. Since you're so knowledgeable, maybe you can point me in the right direction.
And to think I thought it was a piece of cake, lol :-D
#7
Yeah, Matti, that's what I wound up doing. Forgot to post "solved", lol. While I've got your attention, though... Is there a way to check what object is behind another object? Specifically when my char is behind the western wall, where it overlaps with the southern wall, the game just detects the southern wall as being in player.x, player.y, because the southern wall is closer in the z-order. I'm trying to figure this out at the moment, but maybe you or someone else already knows and can save me some hours of thinking (yeah, I'm that slow). Thanks!
#8
Hello, everyone. Continuing with my previous post about making an isometric game... I've got almost everything resolved. Instead of trying to explain how it works and what my problem is, here is a demo game:

Isometric test game

As you can see, the walls become transparent when the player is inside the building (I know there are some minor issues, but I can solve them in the near future). The thing is, that I want to click the hotspots behind those walls (like, for example, the outside chair behind the western wall). If I make the wall unclickable as well as transparent, my whole code goes through the toilet, because it needs the player to be colliding with the wall, so if I make the wall unclickable, no collision occurs, and then the wall just blinks from on to off indefinitely.

Tl;dr: I need to be able to click a hotspot behind a transparent object (wall) without making said object unclickable. Or make it unclickable, but without ruining the rest of the code. I've been a couple hours at it and I can't think of a solution.

Thanks in advance for any kind of help or insight.
#9
Thanks Khris, I understood perfectly. However, I refined my own system, using functions applicable to different rooms without having to write everything over and over. It works 90% as intended, I have only one issue with it. I'm gonna make a new post about it, because the title of the post no longer reflects what I'm having trouble with.

I'm gonna keep your way as a backup in case mine runs into an insurmountable problem later on.
#10
I suspected as much, but I wasn't sure. To be honest, sometimes I'm at a lost, inbetween my noobness and the fact that english isn't my native language. I'm really sorry, you probably think I don't pay attention to your answers. The truth is, I read it at least 10 times. Something was telling me it was the answer, but... I wasn't sure.

Quote from: KhrisOne way to solve this is to split the wall into multiple objects and give each one an appropriate baseline.
I solved this by painting both characters manually, pixel by pixel, but only if what's already on screen is actually behind the character (this requires a secondary, hidden screen, the z-Buffer, were each pixel is used to store distance instead of color).

The simpler method requires to z-sort all characters, objects and wall parts, each frame. However if characters only move from cell to cell, you can simply draw back to front (painter's algorithm).
How would I make this "z-buffer" screen? I've seen a couple videos about this painter's algorithm and I understand the concept now. Should I make a function in the room's rep_exec that checks every object, character and so on in the screen, and makes it visible in the order I want?


I went to sleep and had an epiphany about another one of my "workaround" noobish solutions. I could just make that NPC invisible, and when the player enters the region I talked about, on top of making the south wall transparent, it could make the NPC visible again. If it was an interior room and wall, I could do that with another region, and so on. This probably isn't the better method, because I can't see a way of automating it, and it would be time-consuming. But it would achieve what I want, albeit slower. And I would have to refrain from making random dungeons with isometric views, unless I could somehow make a function that does this automatically.



#11
Well, I've tried understanding the FO code you gave me, and I think I won't be able to pull it off in a million years. BUT there's a little good news. I figured out how to do something resembling what I want, based on Diablo rather than FO. In Diablo 1, the walls where you could walk behind are always transparent, thus you can see yourself, objects, and other characters. That doesn't exactly suit my needs, but I modified it so any given wall makes itself transparent when I'm inside/outside the building (depending which wall we're talking about), by using regions. It might be cumbersome to draw, but it works:
1) I draw the room and the building using layers. Then, I import the whole thing as the room's background, and paint the regions over the appropiate walls. For instance, region 1, in cyan, is drawn on top of most of the south wall, which then becomes transparent when I step on this region (i.e inside the building, south parth of the floor).

2) I replace the room's background with another one, this time without the building (but the regions persist).
3) I make the building using 4 objects, which represent the walls. They sit on top of the regions.


The walls have overriden baselines, so I can sort them by Z-order. But as always, I have an insurmountable problem. If I want a character other than the player to sit inside the building, it just appears drawn like he's outside, sticking to the outside face of the wall (in this example, he's the one wearing a black shirt).


I want him to only be visible when the player enters the building, like this:


I've tried fiddling with his z property, his baseline, but all to no avail. If I could do something like the object's "baseline override", the problem would be solved. But I don't know if it's possible. I can't find a solution anywhere.
#12
Hi Khris! Well, if anybody could do it, it was you :-D
Before I go with my usual round of questions, just answer this one, because if the answer is "no", then all the remaining questions are pointless. Is this too ambitious for a noob like me to pull off? I mean, I can imagine figuring out a simple rhomboid isometric grid, or something. Even if it takes me a week, heh. But I NEED to be able to see behind walls when the character is there. Otherwise it doesn't suit my game's needs. Is this too ambitious?

To the questions:

Quote from: KhrisI happen to have created both a Fallout hexagon "engine" and a standard iso one. For the latter I actually ended up implementing a pixelwise z-buffer since I wanted my characters to be able to move freely on walkable tiles. I almost broke my brain while figuring out how to eliminate the clipping, and it's only possible because each tile shape has a handcrafted depth map:

I understood about 30% of this paragraph :X Although I understand the general idea of what you're saying... What's a depth map? Where does it go in AGS? I'm guessing those green thingies are the tiles and it's "depth", but that's about it. I'm sorry for my ignorance.

Quote from: Khris
If you're fine with the characters' positions being restricted to a tile's center, it's easier to pull off. You'll still have to either break up all walls into pieces or do lots of z-sorting.

I'm fine with them being in the center. Z-sorting the objects, right? That doesn't sound difficult. Maybe time-consuming, but not "my brain can't handle this" difficult. :-D

Quote from: Khris
The Fallout code is simpler and even cuts a round hole into walls in front of the player, but I've not tested it with multiple characters yet.
If you want to take a look, here's the 3.2.1 source: Google Drive

You don't say... I thought a rhomboid/squared grid would be simpler than an hex one. Yeah, I'm totally fine with it just cutting a round hole. I've taking a look at the code, and I have to say, as with most of your more complex codes, it just looks like magic to me... I suppose you wanted me to press F5 and see for myself, but when I do, it says:

Quote from: agsHexagons.asc(306): Error (line 306): Variable 'do' is already defined
BTW, is that code you sent me a working code? I mean, could I use that Fallout engine you made into my own game?
Bottomline, I'm fine using either kind of isometric view, be it the Fallout hex one, or the standard one. Even one without a grid, moving with the mouse (like Baldur's Gate). The thing I have to figure out is the viewing through walls.

As always, thanks a lot for your time and dedication. :)
#13
Hello, everyone! I've been thinking of making my game with an isometric view, like classic old RPGs like Diablo or Fallout. I have a couple questions:
1) Is this recommended? I've read every post about this in the forums, and I seem to recall somebody saying there could be trouble with baselines.
2) Is there any way to be able to see through an obstacle when the character is behind it? Like this:

Maybe make that south wall to be an object, but then... I don't know how would I approach it, and if it's even possible.
3) Is it possible to make a grid system with such a view? So I can move characters around this imaginary grid, etc. For example, Fallout used a hex system. I only want a square grid. Recently, I've made (with help) a grid system for a map room, but that's more straight forward, because it was just a plain aerial view, not isometric.

Thanks!
#14
This is a great explanation, I understood everything now! I'm gonna test this real soon (today I can't) and get back to you. When it works, I'll upload it as a module, crediting you. I don't know how else to repay you, you've been really helpful, I'd even say vital for this part of my project (laugh) Many thanks.
BTW, if I run into a problem, would it be okay to ask you here? I don't want to become a bother.
Cheers! ;-D
#15
Hey Snarky! Thanks a lot for this. It is indeed what I needed, a 2D "map" of the overall dungeon. I'm ashamed to say the following, but, oh well. I'm still learning. Even though I understand the basic idea of your code, I can't figure out were to put it and exactly how to use it. Maybe if I make 50 trial-an-error attempts, I'll finally figure it out, but I'd rather ask you, if you have the time, if you (or anybody reading this) can explain it to me. I'll be very grateful.
Some other questions:
1) #define is like int, but doesn't take memory, or something like that, right? I only know it from seeing it in a forum post, because the manual, afaik, doesn't mention it. Can you modify them like ints?
2) So, with your code, I make a 10x10 dungeon. If I wanted it to be 20x20, would I have to write this?
Code: ags
#define DUNGEON_SIZE 400
#define DUNGEON_DIM_X 20 

3) If I wanted a random sized dungeon, should I just modify those 2 "defines" again? I can figure out how to do it with ints. I'm assuming it's the same method.
4) When the player reaches the boundaries of the maze, let's say the easternmost room, I should just check if the room's X coordinateequals DUNGEON_DIM_X, and if so, turn the right door invisible?
5) About this line of code:
Code: ags
int getDungeonIndex(int x, int y)
{
  return x + y*DUNGEON_DIM_X;
}

I've never seen that usage of an int before. How does that work? Does x reference "dungeonRoomX"?


I realize I've asked plenty of questions. Feel free to answer whenever you can, if you can. Thanks again.
#16
Skip to the end for my code. Not really necessary to read it, and I don't expect anybody to, since it's long. But I post it just in case.

Hello, everybody. I'm making a maze-generator script, because I searched the forums, and even though there are a few posts about this, there isn't any that helps me (either because I couldn't understand java, or links are down, or some other reason). So I embarked myself on doing one. It's "simple": I use a single room, 4 objects as doors, with appear at random when the player enters/leaves the room. When you interact with the top door, you spawn at the bottom door (I make sure the opposite door always spawns; also at least 1 door). You can look at my script a little bit down, but first, my explanation. I tried to make a function that kept track of the previous room. So:
1) I made a struct with a couple bools (door_up, down, left and right), which turn true if the player interacts with the corresponding door.
2) I combined the struct with an array called Dungeon_room (for now, 100), and also made a global int called dungeon_room_number.
3) Made a bool inside the struct, called been_in_room, which turned true when the player left a room. So if been_in_room was false, I randomized the doors. Otherwise, the doors weren't randomized.
4) I was about to keep writing the script so I could return to the previous room. The doors' locations were being kept by the array (as I knew by some test labels I have), so I just had to make the connection. I probably can do that on my own. But then it hit me. I started imagining an already made maze, and the coming back to previous rooms, and I thought of this situation:



You leave room 1 through the top door, then you go to room 3, and 4, and then... If there happens to be a left door in room 4, and you take it, with my code, you'll just end up in a new room 5, instead of the previous room 1, as you should. I can't figure out HOW to make this happen.



Moreover, If one where to backtrack to room 2, and take a left, he would wound up in room 6, then going down to 7, and going right, instead of back to 1, you would go to room 8... So, I started worrying that maybe I can't solve this with my code. So instead of banging my head against the keyboard for 10 hours searching for a solution that might not exist, I'm posting this here.

In dungeon generator.ash:
Code: ags
struct Stats_dungeon_room{ //dungeon room's stats
  bool door_left;
  bool door_right;
  bool door_up;
  bool door_down;
  bool been_in_room;
};

import Stats_dungeon_room Dungeon_room[100];


In dungeon generator.asc:
Code: ags
Stats_dungeon_room Dungeon_room [100];
export Dungeon_room;


In the dungeon room's script (number 66):
Code: ags

function Spawn (this Object*){ //decides whether or not the door will be visible
  door_spawn=Random(1);
  if (door_spawn==1){
    this.Visible=true;
  }
  else{
    this.Visible=false;
  }
}

function door_randomize(){ //generates 1-4 doors.
  oDown.Spawn();
  oLeft.Spawn();
  oRight.Spawn();
  oUp.Spawn();
  if ((oDown.Visible==false)&&(oUp.Visible==false)&&(oRight.Visible==false)&&(oLeft.Visible==false)){
    door_randomize(); //in case no doors spawn, the function runs again, generatin 1-4 doors.
  }
}

//GRAPHICS

function TopBaseline(this Object*){
  this.Baseline=Game.SpriteHeight[this.Graphic];
}

function door_baselines(){ //guarantees you won't be drawn behind a door
 oDown.TopBaseline();
 oRight.TopBaseline();
 oLeft.TopBaseline();
 oUp.TopBaseline();
}


function walk_to_object(this Object*){ //ensures the player walks to the MIDDLE of the door (instead of it's XY corner)

  if ((this==oLeft)||(this==oRight)){
    door_middle=(this.Y-(Game.SpriteHeight[this.Graphic]/3));
    player.Walk(this.X, door_middle, eBlock);    
  }
  if ((this==oDown)||(this==oUp)){
    door_middle=(this.X+(Game.SpriteWidth[this.Graphic]/2));
    player.Walk(door_middle, this.Y, eBlock);
  }
}

function ChangeroomDoor(this Object*){
  if ((this==oLeft)||(this==oRight)){
    door_middle=(this.Y-(Game.SpriteHeight[this.Graphic]/2));
    player.ChangeRoom(66, this.X, door_middle);
  }
  if ((this==oDown)||(this==oUp)){
    door_middle=(this.X+(Game.SpriteWidth[this.Graphic]/2));
    player.ChangeRoom(66, door_middle, this.Y);
  }
}

function door_create_opposite(){ //guarantees the opposing door will be created (e.g if you entered throught the right door, there will be a left door in the next room
  if (door_entered_left==true){
    oRight.Visible=true;
  }
  if (door_entered_right==true){
    oLeft.Visible=true;
  }
  if (door_entered_down==true){
    oUp.Visible=true;
  }
  if (door_entered_up==true){
    oDown.Visible=true;
  }
}



function Enter(this Object*, Object *opposite_door, String opposite_door_string){
  this.walk_to_object();
  
  opposite_door.ChangeroomDoor();
  
  door_entered_right=false;
  door_entered_left=false;
  door_entered_up=false;
  door_entered_down=false;
  if (opposite_door_string=="left"){
    door_entered_left=true;
  }
  if (opposite_door_string=="right"){
    door_entered_right=true;
  }
  if (opposite_door_string=="up"){
    door_entered_up=true;
  }
  if (opposite_door_string=="down"){
    door_entered_down=true;
  }

}



//SETTING IT UP AND INTERACTIONS



function oRight_AnyClick()
{
 oRight.Enter(oLeft, "right"); 
}

function oLeft_AnyClick()
{
 oLeft.Enter(oRight, "left"); 
}

function oUp_AnyClick()
{
 oUp.Enter(oDown, "up"); 
}

function oDown_AnyClick()
{
 oDown.Enter(oUp, "down"); 
}


function room_Load()
{

  door_baselines();
  door_create_opposite();
  player.SetWalkSpeed(30, 30);
  mouse.Mode=eModeInteract; 
  
  if (Dungeon_room[dungeon_room_number].been_in_room==false){
    door_randomize();
  }
  
  if (Dungeon_room[dungeon_room_number].been_in_room==true){
  dungeon_room_number--;
  }
  
}

function room_Leave()
{

Dungeon_room[dungeon_room_number].door_down=oDown.Visible;  /*AKA current room*/
Dungeon_room[dungeon_room_number].door_up=oUp.Visible;
Dungeon_room[dungeon_room_number].door_left=oLeft.Visible;
Dungeon_room[dungeon_room_number].door_right=oRight.Visible;
Dungeon_room[dungeon_room_number].been_in_room=true;


dungeon_room_number++; //going to the next room, so room 1 turns room 2, etc.
}

function room_FirstLoad()
{
dungeon_room_number=1;
}



#17
Quote from: KhrisJust to get this out of the way, since you keep doing it, the variable name room_number is a really bad choice. It's a pointer to a Room instance, NOT a number, i.e. integer.
Yes, I understand that. I named it like that so I can remember what it does, even though I know it's not really a number. Maybe current_room would have been better, idk.
Quote from: KhrisAnyway, converting would only be possible if AGS had an array of rooms
Yeah, I was hoping such an array existed, like with objects. Bummer. :(
Quote from: KhrisWhich means there's only one available .
I suspected as much, but I wasn't sure.
Quote from: Khrisyou need to schedule the random placement, then call it in your on_event/eEventBeforeFadein block if (this.Room == player.Room), i.e. the player has entered the room the character is currently in, too.
That's what I was trying to avoid, since this only happens when the player encounters a "random encounter" in a map room (you probably figured out I'm making a sort of RPG/adventure hybrid), therefore I only need this to happens in like 30, 40 rooms. I'll probably use a room property and call it from on_event only if the player is in a room with such a property. I guess the objective of this post was to find out if an array of rooms existed, or if there was any way of converting room to int. There isn't, though luck. (laugh)

Thanks again, Khris. And thanks for everything. Since I've come back to AGS I've learned to do a lot of things from you. I wouldn't be making this game if it wasn't for your help. Be sure you're gonna have a huge thank you in the credits! (nod)
#18
Hello, everyone. I'm trying to make an extender function to place my characters randomly in any given room, and later call it from on_event. If all my rooms where the game resolution, it wouldn't be a problem. But I want this to work with my many scrolling rooms, so i figured I would use the Room.Width and Height commands. The thing is, I don't know how to convert an int (Character.Room) to a "Room*" (so I can use Room.Width/Height). Maybe there's even a better way to approach this, but I can't figure this out.

Code: ags
function PlaceRandomly(this Character*){
  Room* room_number = this.Room; // <--- This is my problem: Type mismatch: cannot convert 'int' to 'Room*'
  this.x=Random(room_number.Width);
  this.y=Random(room_number.Height);
  this.PlaceOnWalkableArea();
}
#19
Hi Khris! Long time no see. It worked! As always... Thank you!!

A couple of optional follow-up questions, answer if you have the time and the inclination, if not, I can live with that (laugh)
1) I moded the code because it was giving me negative numbers. Still, it starts counting at the bottom right grid (as in, the bottom-right square is 260, and the top-left square is 1). I would like for the top-left to be 1.
Code: ags
  int x = (2560-player.x) / grid_width; // replace OX, OY with coordinates of grid in room
  int y = (1600-player.y) / grid_height;
  grid_current = y * 20 + x + 1; // start counting at 1

2) Could you show me how to do it with "for"? I thought it was what I needed, but I can't understand the manual's explanation. :(


P.s: I imagine some day you're gonna stop pointing that gun at the roof and shoot me. (laugh)
#20
Hello, i'm making a map with a grid system. In each of the grids, different things happen. I track the grid the player is in with the int "grid_current". The thing is, I can't figure out how to make the grid_current change according to the player's coordinates. I mean, I do, but manually. And I don't want to have to write 250 of those, I'm sure there's an easier way.

grid_width is another int which tracks the, well... grid's width (laugh) I have another one for grid_height, but right now I'm making the 1st row of grids. I'm sure I can extrapolate from the width.

My code so far is this:
Code: ags
  
if ((player.x>=grid_width*1-1)&&(player.x<=grid_width*1)){ //the player is in grid 1. his X coordinate is bigger than the left side of the grid, and smaller than the right side of the grid.
    grid_current=1;
  }
else if ((player.x>=grid_width*(2-1))&&(player.x<=grid_width*2)){
    grid_current=2;
  }
else if ((player.x>=grid_width*(3-1))&&(player.x<=grid_width*3)){
    grid_current=3;
  }


I call the function in room_repexec. It works, but as I said, I'm sure there's a way to make it automatic.

Thanks in advance.
SMF spam blocked by CleanTalk