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 - hocuspocus2

#1
Sorry for the late reply, I use version 3.5.0. I tried adding an IsKeyPressed() to the rep exec always, but it seems to be a bit buggy. Even when it does pause the game, clicking the mouse still triggers the Saying function when it's in a cutscene (ie when there's multiple lines "queued" or when the player goes to a different room right after the dialogue).
I like the pressed key code return value idea, but I'm currently a bit wary of using 3.6.0 on my game when it's in beta, so I think I will put this issue in the backburner of my game's todo list until the 3.6.0 official release.
#2
I have a custom Say function that's like this:
Code: ags

void Saying(this Character*, String msg) {  
  gSpchWindow.Visible = true;
  lSpeechText.Text = msg;
  lSpeakerName.Text = this.Name;
  
  while (WaitMouseKey(40) == 0 && !Game.SkippingCutscene) { // wait until key or mouse click
  
    /*...Irrelevant animation code...*/
    
  }
  
  gSpchWindow.Visible = false;
}


This function works fine. The problem is with WaitMouseKey, in that during a cutscene with lots of dialogue, I'd like the player to be able to pause the game during the cutscene (by pressing P, for example). Pressing P during a cutscene while the speech GUI is visible doesn't do anything, it just treats it like any key press. So I was wondering how I could have the WaitMouseKey in this code ignore certain keys?

In truth, I was originally trying to have the function only respond to mouse clicks and the Enter key, instead of responding to any mouse clicks/key presses. I tried to do it by modifying the loop to something like:
Code: ags

while (!Mouse.IsButtonDown(eMouseLeft) && !IsKeyPressed(eKeyReturn) && !Game.SkippingCutscene) {
  while (WaitMouseKey(40) == 0) {
   /*....*/
  }
}

Which I suppose worked with the speech aspect, but would also cause some bugs in other areas, and not "queue" speech lines.
#4
Yeah, I know I can put custom functions in other scripts, but can I move special functions from the global script to extra scripts? The manual does say they can contain on_event, on_mouse_click, etc.
#5
Ah ok, thank you for clearing it up. The drawer inv. pops up after clicking on a hotspot and it has a close button, so that way you can look at both your inventory and the drawer's.
I was hoping I would do all the storage work in rooms, because my global script is already getting cluttered and I'm not even 25% done with the game yet. I guess the best I could do is write a function as a shortcut for the code with GUI and GUIControl parameters, and use it for each drawer inv in on_event. (because there's gonna be a lot in the game).
Either way, I moved the current code to on_event, modified it, and it works now. Thanks for the help!
#6
My mistake, I added the button if-statement from your code example. Here's the thing, when I transfer an item from drawer inv. to player inv., it works. But not vice versa. The Display command also never triggers.

Code: ags

function on_mouse_click(MouseButton button) {
  GUIControl *ctrl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  InventoryItem *item = inventory[game.inv_activated];

  if (ctrl == InventoryStorage1) {
    if (button == eMouseLeftInv) {
      ClaimEvent();
      
      if (item != null) { //Taking item from storage, works fine
        player.AddInventory(item);
        cStorage1.LoseInventory(item);
      }
    
    } else if (button == eModeLeft) {
      if (player.ActiveInventory != null){ //Putting item in storage, does nothing
          ClaimEvent();
          
          Display("Switching player and adding item!");
          cStorage1.SetAsPlayer();
          cStorage1.AddInventory(item);
          
          cRoger.SetAsPlayer(); //Player character
          player.LoseInventory(item);
        }
    }
  }
}


Edit note: I also found this discussion on Github relevant. So I guess it's not possible to click on empty inventory slots (unless if using on_event or eEventGUIMouseDown like the post suggested)?
#7
You mean "Override built-in inventory window click handling", right? I do have it set on True already. I should also mention that I'm using the BASS template, I think.
Also changing "button" to eMouseLeftInv or anything else in on_mouse_click causes a parser error, unless if I'm doing it wrong.
#8
Hello, sorry for the late reply, I was trying to figure it out before responding. I'm trying to follow your first suggested method, I'm just stuck at the character switching part.
I'm trying to make it so that the player drags their item to the drawer inventory and clicks on an empty slot to transfer said item (and vice versa). I've managed to switch characters (from player to drawer dummy, cStorage1), but I can't get it to trigger on mouse click.
Does mouse_click not work in room scripts? Or maybe I'm approaching this wrong? Because putting this code in room_RepExec switches player character when your mouse is just hovering over the drawer inv. GUI.

Code: ags

function on_mouse_click(MouseButton button) {
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == InventoryStorage1) {
    if (player.ActiveInventory != null) {
      cStorage1.SetAsPlayer();
    }
  }
}
#9
The player will have a limited number of inventory (10 items), and so they would need to store extra items in drawers and such and then take them out if needed. They essentially work like backpacks in some video games. This will probably be achieved using multiple inventory GUIs, the problem is I'm not sure how I would go on about it. I'm thinking that I would need to create dummy characters for each drawer, but that's about it.
I should mention that this is a 1st-person perspective (so the player character is hidden).
#10
Hello, I have a room where there would be a complicated chemistry puzzle that the player uses to create items, like Black Ink or Glue. I started coding it myself, but I felt stumped on how to do this properly. I also feel like it's just spaghetti code and possibly needs a complete do-over. So, I need someone to help me code the puzzle and get it working, it's not a long-term role really but just for this room.

I've written the notes in a Doc, with screenshots: https://docs.google.com/document/d/140oAEoX2QuQRPyNveGJUfuvQU_DnU0K_vQgvTJVF33k/edit?usp=sharing
Here's a Doc of the current code, I tried my best to format it nicely: https://docs.google.com/document/d/18HxjUeciVUCoa7UVTIjqfzNOglsUbvrs3ji8OlJKYU8/edit?usp=sharing

You can reply to this thread or PM me, but I think I prefer replies.

If you need any more details, let me know and I will add it to this post.
#12
I'm trying to have a global function that resets an int array's elements, like so:
Code: ags
void resetIntArray(int array[], int n, int indexNum) {
  for (int i = 0; i < n; i++) 
    array[i] = 0;  
  indexNum = 0;
}


then imported it in the header:
Code: ags
 import void resetIntArray(int array[], int n, int indexNum = 0);

but when I try to use it locally it gives me the error:
Code: ags
Error (line 43): Type mismatch: cannot convert 'int*' to 'int[]'

I would use it like this:
Code: ags
resetIntArray(playerInput, 9, indexNum);

where playerInput is an int array of 9 elements.

I think playerInput is the problem. Am I supposed to pass it a different way in the argument?
#13
Yeah sorry, I still haven't gotten around to learning how custom functions work in AGS. I got into some confusion and errors, but I finally got it to work, thanks!
#14
It doesn't seem to be doing anything. To test, I tried changing new_h and new_w to something tiny, commenting the if statement that deletes ActiveItemCG, moving the whole code to different places, messing around with ds.DrawImage parameters, and it doesn't give any different results (except for some errors). Just to check, the code is supposed to go outside of a function, right?
#15
I tried your example code in Global Script and it says ".Graphic' is not a public member of 'DrawingSurface" which refers to line 17. I looked in the manual and it doesn't seem like DrawingSurface has a .Graphic anywhere.
#16
I have "Use selected inventory graphic for cursor" to true. What I want to happen is that the item's cursor graphic would be scaled down so it looks smaller than its graphic in the inventory bar, but they're still essentially the same sprite/image. In my case, each item's sprite is 100 x 100, and I want its cursor graphic to be scaled by half, so 50 x 50 (might change my mind and make that bigger though, like 70 x 70).
I know I can probably redraw each item as smaller, then set that as its cursor graphic in the editor's inventory item menu. But I feel like that would take too much space and time when I can just globally script the scaling. I tried using DynamicSprite* and Overlay*, but I think they're too complicated for me. I just kept getting errors, and I kinda didn't know what I was doing.

#17
Ok, so I finally figured it out.
I loaded up a new game with the BASS template and compared its scripts with mine. I've found that some template functions and statements were missing from mine, which was strange as I could have sworn I didn't delete anything and instead commented any lines in GlobalScript I wasn't using. One line in my game's TwoClickHandler.asc was also missing:
Code: ags
import static function Close();
As I still don't know what script headers really do, I never dared to tamper with them, so I have no idea why it was missing.

After correcting the game's TwoClickHandler and Global scripts, the items' Interact and LookAt functions started working. It didn't switch the cursor graphic though, and didn't work on a hotspot. That's when I found out that, when I was trying to investigate the problem, I've set the template's item property "InstantUse" to true, as I didn't know what it did beforehand. Now, the items switch the cursor graphic and work just fine.

My edge's cursor code was also interfering, where it switches back to eModePointer too quickly, so I modified it:
Code: ags
function repeatedly_execute() {
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeLeft);
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeRight);
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeDown);
  } else Mouse.UseDefaultGraphic();


It basically changes the cursor graphic alone instead of switching to a different mode if mouse is on an edge, and otherwise changes to DefaultGraphic.
#18
It worked! I can finally navigate to Room 35 after all this time. Thanks!
#19
Ok, thank you for investigating this. I did try to add ClaimEvent() after every Room.ProcessClick line, but it seems to interfere with the edges code on the on_mouse_click function and it didn't work, so I couldn't navigate to Room 35 initially.
So I changed the player's starting room to 34, and the hotspot that leads to Room 35 does work. Maybe I should modify the edges code?
#20
I did try the BASS template by itself and it worked.
I'm gonna try Cassiebsg's advice, and if that doesn't work then I guess I will have to start over :(
SMF spam blocked by CleanTalk