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

Topics - johanvepa

#1
I just can't seem to get arrays right.

I am trying something that should be real simple and works if I just name all the characters one after the other, but I want to do it using arrays.

Whats wrong with this simple piece of code?? I am told there's a null pointer reference. But I assigned a value to the pointers. I don't understand.

In globalscript:
Code: ags
Character *trash[12];
int trashcounter;

function removetrash()
{
  trashcounter = 1;
  while (trashcounter < 3)
  {
    if (trash[trashcounter].Frame == 4)
    {
      trash[trashcounter].x = 1;
      trash[trashcounter].y = 1;
      trash[trashcounter].Frame = 0;
    }
    trashcounter ++;
  }    
}

function repeatedly_execute() 
{
  removetrash();
}

function game_start() 
{
  trashcounter = 1;
  trash[1] = cAffald1;
  trash[2] = cAffald11;
  trash[3] = cAffald12;
}


#2
Last one for the evening (roll)

At a certain point in my game, I'd like a certain character to animate while moving towards another character. Not the walk command, since the animation is to be done only once (if it repeats it'll look silly). The animation is that of disappearing into the other character.

trash is a Character variable. itemcarried determines if the relevant other character is currently in position. This all works.

Code: ags
function catchtrash()
{
  if ((trash != null) && (trash.Frame == 0) && (itemcarried != cTrashbin))
  {
    trash.ChangeView(2);
    trash.Animate(1, 4, eOnce, eNoBlock, eForwards); //nÃ¥r animation er bagved move, vil den ikke move
    trash.Move(cTrashbin.x, cTrashbin.y, eNoBlock, eAnywhere); //nÃ¥r move er bagved animation, sker der noget med animation
    cTrashbintimer = 0;
    GiveScore(1);
    bScore.Text = String.Format("%d", game.score);
  }
}


If trash.animate is set to operate after trash.move, then it animates but doesn't move. This is explained in the manual that the move command is stopped by the animate command. So that makes sense. I try to get around it by putting trash.animate before trash.move.

The strange things:
If trash.animate is set to operate before trash.move, then the trash moves and animates, but it animates twice. First it animates while moving, then it animates again.

There are several characters that can be the variable trash. If the function operates first on one of these characters, then another, then the first character to be 'trash' will operate as described, moving but animating twice. If another character is then subject to being 'trash', then the animation first plays without moving, then it moves while animating again, and finally it animates a third time.

Any thoughts?
#3
Somewhere in my script I wisd to use an animation that does not block the whole script from continuing, but I would like some things to wait for the animation to end. Like, in my tower game I have this for whenever the character cAffald1 is hit and should first do its little death animation, then be placed somewhere else "out of the game".

Code: ags
function cAffald11_Look()
{
cAffald11.StopMoving();
cAffald11.ChangeView(2);
cAffald11.Animate(0, 4, eOnce, eNoBlock, eForwards);
a4.Play();
GiveScore(1);
bScore.Text = String.Format("%d", game.score);
cAffald11.x = 1;
cAffald11.y = 1;
}


What happens here is that cAffald1 moves to x=1, y=1 immediately and I cannot see its death animation. But if I use eBlock, then everything else stops, which is not good.

I could put something in rep_exec_always, but that seems and unsatisfactory solution to some other way to make the execution of function cAffald11_Look() simply wait its turn.

How to?
#4
Is there an easy way to determine if the visuals of two characters are overlapping? Like AreThingsOverlapping, but without being triggered by transparent parts of the characters?
#5
I am doing a check to see if things are overlapping. I have two character, one stationary called ctrashbin, and one moving, called cAffald1. Every game cycle, I wish to see if they overlap, then something happens.

Code: ags
  if (AreThingsOverlapping(cTrashbin, cAffald1))


When trying to compile, I am told there is an error at the line: Cannot convert 'Character*' to 'int'.

Me no unnerstand?
#6
In my little tower defense game, I want a feature where one can pickup items (made as Characters in AGS, not objects or inventory items) and drag them (mouse button held down) to another part of the screen, then drop them there (release mouse button). If the intended place for drop is not suitable, the item returns to its place of origin.

This is simple enough. I couldn't find a feature already in AGS that does this, so I did the following:

In globalscript:
Code: ags
Character *itemcarried;
export itemcarried;

function cTrashbin_PickUp()
{
itemcarried = cTrashbin;
}

function cBrikker2_Interact()
{
  if (itemcarried == cTrashbin)
  {
    cTrashbin.x = cBrikker2.x;
    cTrashbin.y = cBrikker2.y;
    itemcarried = null;
  }
}


In local script:
Code: ags

import Character *itemcarried;

function room_RepExec()
{

    //to pick stuff up and let it follow the mouse cursor
  if (mouse.IsButtonDown(eMouseLeft)) //if button is down, something is supposedly being carried
  {
    if (itemcarried == null) //in the instance nothing yet is assigned as the item carried :
    {
      if (IsInteractionAvailable(mouse.x, mouse.y, eModePickup))//if something is there to be picked up (in the globalscript this is possible for the cTrashbin):
      {
        ProcessClick(mouse.x,mouse.y, eModePickup); //in the event script for cTrashbin, this assigns cTrashbin as 'itemcarried', item will no longer be == null:
      }
      else //else if nothing is there to pick up, do no more about the mouse cursor pressed down:
      {
        return(0);
      }
    }
    else //if button is down and something is assigned as the item to be carried
    {
      //then each game cycle, the itemcarried's coordinates should be the mouse coordinates
      itemcarried.x = mouse.x;
      itemcarried.y = mouse.y; //The issue: when assigning the mouse y-coordinate as the itemcarried's room y-coordinate, the two does not match. I need to adjust value for the item's room y-coordinate
    }
  }
  else //if noone is holding the mouse button down
  {
    if (itemcarried != null) //in the instance a character is assigned as the itemcarried but the mousebutton is not down. This will happen if someone is releasing the mouse button after carrying stuff
    {
      if (IsInteractionAvailable(mouse.x, mouse.y, eModeInteract)) //if mouse coordinate (not item coordinate) is above a place where interaction is possible (in the script, a character that may be interacted with, i.e. the character cBrikker2)
      {
        ProcessClick(mouse.x,mouse.y, eModeInteract);//then run the eModeInteract script with that character
      }
      else //in the instance there is an item assigned to Character *item but there is nothing to interact with at the place the mouse button is released
      {
        itemcarried.Move(cBrikker1.x, cBrikker1.y, eNoBlock, eAnywhere); //move the item back to starting point
        itemcarried = null; //no 'item carried' any more
      }
    }
  }

//any other business
}


This works fine.


Issue
The background is larger than the screen to allow for characters walking in from outside the screen boundaries. So I have to add 95 to the y axis and lock viewport.

In order for 'Character *item' (in the example cTrashcan) to appear alongside the mouse cursor, and not 95 pixels away from it, I have to add to the y axis assigned to the coordinates of itemcarried in the above script.

And so, this part of the code
Code: ags
    else //if button is down and something is assigned as the item to be carried
    {
      //then each game cycle, the items ccordinates should be the mouse coordinates
      itemcarried.x = mouse.x;
      itemcarried.y = mouse.y; //Problem: when assigning the mouse y-coordinate to the item's room y-coordinate, the two does not really match. I need to add some value to the item's room y-coordinate
    }

could look like this to adjust the itemcarried's room coordinates:
Code: ags

    else //if button is down and something is assigned as the item to be carried
    {
      //then each game cycle, the items ccordinates should be the mouse coordinates
      itemcarried.x = mouse.x;
      itemcarried.y = mouse.y+110; //Problem: when assigning the mouse y-coordinate to the item's room y-coordinate, the two does not really match. I need to add some value to the item's room y-coordinate
    }


This should be simple. It works, meaning that itemcarried now appears alongside the mouse cursor. Problem: For some reason, the interaction with the character cTrashbin that in globalscript should trigger this:
Code: ags
function cTrashbin_PickUp()
{
itemcarried = cTrashbin;
}

just doesn't happen. Instead, the itemcarried returns to its poont of origin, as if there was nothing to interact with at the mouse coordinates.

If I take away "+110" from the itemcarried's room coordinates again, then it works fine.

Seemingly, the change in the room coordinates of 'itemcarried' changes how the mouse cursor interacts, but th emouse cursor's coordinates are not changed, only cTrashbins room coordinates are changes. I don't understand.

#7
I am making a simple tower defense game, and a feature is that the mouse cursor changes with whatever region it is hovering over. The code is this:
Code: ags

function room_RepExec()
{
  if (Region.GetAtRoomXY(mouse.x, mouse.y) == region[1])
  {
    if (mouse.Mode != eModePickup)
    {
      mouse.Mode = eModePickup;
    }    
  }
  if (Region.GetAtRoomXY(mouse.x, mouse.y) == region[3])
  {
    if (mouse.Mode != eModeLookat)
    {
      mouse.Mode = eModeLookat;
    }
  }


This works, but with huge performance issues. The mouse cursor does not always change, it stays in eModePickUp even when hovering over region [3]. After a while it changes, so the code is recognized, but it takes long time for the game to realize. The issue is varying, sometimes it changes more quickly than other times.
Any ideas?
#8

I am doing a function that checks if the mouse hovers over a region. If it does, and the cursor is not PickUp, then it should change to PickUp.

I am doing this:
Code: ags




function room_RepExec()
{
  if (Region.GetAtRoomXY(mouse.x, mouse.y) == Region[1])
  {
    if (mouse.Mode != eModePickup)
    {
      mouse.Mode = eModePickup;
    }
  }


since the manual told me this is a correct example:
if (Region.GetAtRoomXY(player.x, player.y) == region[0])
  Display("The player is not currently standing on a region.");

But AGS tells me that Region is not an array. What is wrong here?
#9
I remember the original Quest for Glory II had a nice feature where walking in the desert would cause the background to change by a quick sideways scroll from one screen to the other, rather than fading. This looked quite nice, I thought, and for backgrounds that fit nicely into each other without wanting the background to scroll as the players walk around, this is a nice touch to a game.

But how to do that?
#10
Will the event function on_mouse_click register the mouse click as soon as mouse button is pressed or only when it is pressed and released? Will on_mouse_click be called if I press and hold the mouse button?
#11
I find that my test audience expect the "grabbing an item and moving it" to work like a smartphone and so they try to pickup by holding the mouse button pressed and releasing by releasing the mouse button. Rather than explaining the issue of "click the mouse to pick up, click again to release", I'll instead try to conform the game to the audience.

This calls for AGS to recognize in repeatedly_execute that a mouse button is pressed. Sort of like a bastard between IsKeyPressed and on_mouse_click.

Is this possible?
#12
My test player has trouble picking up items (objects or characters) as they look quite small on the screen and she has to be careful when positioning the mouse cursor over the item in question. I'd like to sort of "increase mouse sensitivity area" when it comes to mouse clicks and IsInteractionAvailable functions. Is this possible?
#13
I'm trying to make a function that enables me to make a character follow the mouse cursor around. I also need to turn that function off and on in the game.

This works fine with a bool and a small funtion. In global script:
Code: ags

bool shovelfollowingcursor;

function repeatedly_execute() 
{
  if (shovelfollowingcursor == true)
  {
    cShovel.x = mouse.x;
    cShovel.y = mouse.y;
  }
}

function cShovel_PickUp()
{
  shovelfollowingcursor = true;
}


Now I want to extend this to more characters to pick up and follow the cursor around. I figured something like an integer that keeps track of which character is the one I want to do this and then a function to make character[integer] follow the cursor, but I get the message that I cant convert character* to integer.

How do I make a function recognize a character by way of a global integer value?



#14
I want eModeUseinv to have one cursor graphic as default and another graphic when hovering over certain hotspots or objects. This works just fine (thanks everyone for help with the coding in another thread). As it is, my cursor graphic is the default at whatever position on the screen, however when hovering over a hotspot, another cursor graphic makes the inventory item seem highlighted in some way (still playing around with designs).

But I use a lot of sprite slots and its tedious work to make two graphic sprites for every inventory item (one default and one highlighted). Is there a function in AGS that can make a graphic seem different in some way? Of course I can tint the graphic sprite using dynamic sprites, but I'm not reaaly satisfied with tinting. I want something like creating an outline around the object or changing a graphic sprite to grey shades.

Is there a solution that might do something like that?



#15
There's a lot of things I dont understand about the inventory window.

I am trying to create a game with a perpetually open inventory GUI on the right side of the screen. I plan for the user to select items from the inventory window, then use items directly onto the game screen without opening and closing the inventory GUI.

My default cursor is eModeInteract since there will be no walking around in this game.

I can select an inventory item with the mouse cursor, and the cursor changes into the mouse cursor graphic of that inventory item. I can then use said inventory item on hotspots and objects as usual.

But, I also want other things to happen when I click on the inventory items with the eModeInteract mouse cursor.
This is where it gets strange. Even though I script for something to happen when interacting with inventory item, it doesn't. At the event handle panel for a given inventory item, like my iAcorn, I put something in the global script to happen for the event of "Interact inventory item" (and yes, I have remembered to use the event control panel of the item as well). When clicking the mouse cursor (in eModeInteract) at the image of iAcorn on the inventory window, the cursor changes to the CursorImage of iAcorn, but nothing else I scripted happens.
I dont understand why not?

Also, if I make a default cursor graphic for eModeUseinv, the cursor hotspot insists on being at 0,0 instead of the cursor hotspot coordinates I give it. Why wont the cursor hotspot obey?

And yet another thing: For experimenting, I put something in the item's event panel to happen when player should "Look at inventory item". Now, if I right-click on the inventory item, the designated stuff to happen for "look" happens, even though I am not using the eModeLookat cursor and there is not even anything scripted to happen for right-clicks in my game (I am using the blank game template and have nothing scripted for any right-clicks). Yet right-click makes the player look at the inventory item. Huh?

I understand nothing. Me no unnerstand.

I consider re-writing an inventory GUI from scratch using buttons and such, but its timeconsuming. I'd much rather understand why the inventory window doesnt act the way I would expect?
#16
In the standard game template, the inventory GUI has an InventoryWindow. When selecting an item on this window, the cursor changes to that of the item, and that is well.

I want the GUI to disappear right when I select an item, not only when clicking the button btnInvOk. How can I change this?
#17
I have put a neat little feature in my christamas spoof for the office where, whenever the mouse moves over a certain hotspot, the cursor changes. I use the mouse.Mode = eModeUseInv and change the players active inventory accordingly with functions like "hHotspot2_MouseMove()". That has worked so far.

However, in a certain room I put some objects that cover the entire room, and now the hotspots seem to be "missing" in some way. At least the game somehow no longer reacts to the mouse being on top of the hotspots.

I also tried making the game check for mouse x,y-coordinates in rep_exec, and change the cursor and mouse mode whenever mouse position was at certain location. This doesn't work either.

I have a feeling that the objects that cover the screen somehow prevent other functions from carrying out. What could be causing this?
#18
For the sake of an argument, is it possible to make a game run in, lets say, 400 x 300 pixels?
#19
Using AGS for a christmas surprise at work, I wonder if I can make AGS open a pdf file for the user?

I'm looking for a command that does something like opening the PDF file in the background, then quitting AGS so the PDF file is open and visible to the user when AGS closes.

Is this possible? I believe the function File.Open might not be what I'm looking for...?
#20
All my buttons have grey background by default, and white and black outlines. I can't seem to change them into anything else other than by giving them an image. But this seems impractical when there are lots of buttons. Is there a way to make the background color of buttons white? And while we're at it, is there a way to change the outline of a button from the black and white lines into something else?
SMF spam blocked by CleanTalk