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

#21
Ok, I have another problem when im trying to save tiledata to a file.

Code: AGS
if (keycode == eKeyF5) {
File *output = File.Open("tiles.dat",eFileWrite);
if (output == null) Display("Error opening file.");
else {
  int tx = 0; int ty = 0;
  while (ty < 15) {
    while (tx < 20) {
      output.WriteInt(tiles[ty].x[tx]);
      tx++;
    }
  ty++;
  }
output.Close();
}
}


if (keycode == eKeyF6) {
File *input = File.Open("tiles.dat",eFileRead);
if (input == null) Display("Error opening file.");
else {
  int tx = 0; int ty = 0;
  while (ty < 15) {
    while (tx < 20) {
      tiles[ty].x[tx] = input.ReadInt();
      tx++;
    }
  ty++;
  }
input.Close();
}
}



It should work that pressing f5 saves tiles[].x[] to tiles.dat and f6 loads the stored data back to tiles[].x[]. But from some reason when I load the stored data, only first row of the data is returned (that means tiles[0].x[from 0 to 20]). Values in tiles[1].x[], tiles[2].x[]... are 0. Code is short and simple so the problem should be easy to fiqure out but i just dont see it.

tiles[].x[] is like this:

Code: AGS
struct TileDataSt {
int x[20];  
};

TileDataSt tiles[15];
#22
Thanks for quick reply. Moving wait to outer loop did the job.
#23
Im doing level editor for my tilebased game. Level is drawn to the background and then exported as a bmp file. The problem is that one command in the editor is supposed to fill entire background with the selected tile graphic. Drawing works fine but the background doesnt update. I can update background by using wait command between code but id like to know if there is more proper way to do it. And id like to understand how drawingsurface works and why it doesnt update background rightaway.

Without wait command background updates only if I for example move character on the screen and the area where character moves is updated.

if (keycode == eKeyCtrlF) {
ViewFrame *frame = Game.GetViewFrame(CURSORVIEW,  0, 0);
DrawingSurface *mainBackground = Room.GetDrawingSurfaceForBackground(0);
int tx = 0; int ty = 0;
while (ty < 480) {
  while (tx < 640) {   
    mainBackground.DrawImage(tx, ty, frame.Graphic);
    //Wait(1); IT WORKS IF I USE WAIT COMMAND HERE BUT IT SLOWS THE EDITOR
    tx = tx + 32;
  }
  tx = 0;
  ty = ty + 32;
}
mainBackground.Release();
}
#24
Quote from: Khris on Thu 07/02/2013 21:05:07
You don't need an OK button nor to script the handling of the enter keypress; if you press enter while a textbox is active, its OnActivate function gets called.
Just double-click the textbox or create/link the function in its events pane, like you would with a button.

Okey, my bad. Didnt read this carefully enought. The original script didnt work because OnActivate function overrides the on_key_press function. Now its working, when I moved the code to the right place.

Thanks.
#25
Thank you all.

Quote from: geork on Thu 07/02/2013 20:35:32
Hope that helps!

Seems like a good idea. Thanks.

Quote from: Khris on Thu 07/02/2013 21:05:07
You don't need an OK button nor to script the handling of the enter keypress; if you press enter while a textbox is active, its OnActivate function gets called.

Good point, I guess I could do this also without the button. But Im still interested why the original code didnt work.

Quote from: Khris on Thu 07/02/2013 21:05:07
The reason I suspect why what you tried doesn't work:
If the GUI's visibility is set to "pause game when shown", the default on_key_press function will exit at about midway (due to the game being paused), so if you added your line near the end, it never got processed in the first place.
GUI's visibility is set to "Normal, initially off". At the point where enter key is pressed GUI is visible.


Quote from: Crimson Wizard on Thu 07/02/2013 20:57:50
What exactly the problem is: the code does not compile, or fail to run?

Sry, forgot to mention that. So the code compiles just fine, but the problem is that game seems to ignore the function call. (if (keycode == eKeyReturn) player.Say("Hello.")) worked right.

Quote from: Crimson Wizard on Thu 07/02/2013 20:57:50
What code do you have inside "OnClick" function? What will happen if you put some "Display" call in the beginning of OnClick, showing test message?
On click works when I click the button with mouse (Also displays the test message) but when I press enter, nothing happens.

BtnDevelopOK is in gDevelop gui and it processes different actions depending the value of DevelopGUI variable. There is a textbox inside this gui and when you press the OK button, it converts Textbox.Text to Integer.
Code:
Code: AGS
function BtnDevelopOK_OnClick(GUIControl *control, MouseButton button)
{
if (DevelopGUI == 1) {
  Cash = TxtBoxDevelop.Text.AsInt; 
  LblDevelop.Text = ("Done!"); 
  DevelopGUI = 0;
  TxtBoxDevelop.Text = "";
  TxtBoxDevelop.Enabled = false;
  SetUpInventory();
}
else if (DevelopGUI == 2) {
  if (TxtBoxDevelop.Text.AsInt < 1 || TxtBoxDevelop.Text.AsInt > 639) DevelopX = player.x;
  else DevelopX = TxtBoxDevelop.Text.AsInt;
  LblDevelop.Text = "Set Y (0 to keep current Y):";
  DevelopGUI = 3;
  TxtBoxDevelop.Text = "";
}
else if (DevelopGUI == 3) {
  if (TxtBoxDevelop.Text.AsInt < 20 || TxtBoxDevelop.Text.AsInt > 479) DevelopY = player.y;
  else DevelopY = TxtBoxDevelop.Text.AsInt;
  LblDevelop.Text = "Set room:";
  DevelopGUI = 4;
  TxtBoxDevelop.Text = "";
}
else if (DevelopGUI == 4) {
  if (TxtBoxDevelop.Text.AsInt > 0 || TxtBoxDevelop.Text.AsInt < 4) {
  LblDevelop.Text = "";
  DevelopGUI = 0;
  player.ChangeRoom(TxtBoxDevelop.Text.AsInt, DevelopX, DevelopY);
  TxtBoxDevelop.Text = "";
  TxtBoxDevelop.Enabled = false;
  }
}
}


Quote from: Crimson Wizard on Thu 07/02/2013 20:57:50
Also, what other code do you have in "on_key_press"? In other modules maybe (if you have any)? Is the Return key is being handled earlier in the function somehow?

Here is the on_key_press (No other modules there):
Code: AGS
function on_key_press(eKeyCode keycode) 
{
  if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
  
  if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  if (keycode == eKeyF9) RestartGame(); // F9
  if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
  
  if (keycode == eKeyX && gDevelop.Visible == false) {gDevelop.Visible = true; DevelopGUI = 0;TxtBoxDevelop.Enabled = false;}
  else if (keycode == eKeyX && gDevelop.Visible == true) gDevelop.Visible = false;
  
  if (keycode == eKeyReturn && gDevelop.Visible == true && TxtBoxDevelop.Enabled == true) BtnDevelopOK_OnClick(BtnDevelopOK, eMouseLeft);
  
  if (keycode == eKeyI) {
    if (gInventory.Visible == true) CloseInventory();
    else {
      SetUpInventory();
      LastMouseMode = mouse.Mode;
      mouse.Mode = eModeWalk;
      mouse.DisableMode(eModeInteract);
      mouse.DisableMode(eModeTalkto);
      LblInvInfo.Text = "";
      gInventory.Visible = true;
      }
  }
}
#26
Quote from: Billbis on Thu 07/02/2013 20:25:43
Did you try ProcessClick (int x, int y, CursorMode) ?

I saw that function while I was looking for answer and I guess it would work too. But from what I red for example here, I understood that it should be possible to do by calling the "OnClick" function and Id like to use that way if just possible, because it just seems more "right" way to do it.
#27
Hi. Im trying to manually call a button click function by pressing the enter key, but for some reason i dont get it working.

Also Id like to know what "GUI Control *control" parameter exactly does and what I should write at that section.

Im quite tired now so I hope Im not just missing something stupid, but I couldnt find clear answer from search or manual.


I have this in "on_key_press" function:
Code: AGS
if (keycode == eKeyReturn && gDevelop.Visible == true && TxtBoxDevelop.Enabled == true) BtnDevelopOK_OnClick(BtnDevelopOK, eMouseLeft);


And this function somewhere above it:
Code: AGS
function BtnDevelopOK_OnClick(GUIControl *control, MouseButton button)
{
...Some code...
}


I have tried this with and without putting the "OnClick" function to import and export (Do I need to?). And tried also without "gDevelop.Visible == true && TxtBoxDevelop.Enabled == true" inside if section, but none of those didnt work.
SMF spam blocked by CleanTalk