More regions..

Started by Slasher, Sun 14/06/2015 15:28:52

Previous topic - Next topic

Khris

I assume that number[dieRoll] is an int, not a String? In that case you need to use %d, not %s.

Snarky

In the code snippet I provided it's a String:

Code: ags
String number[7];
 
// Call this up front, along with initBoard()
void initNumbers();
{
  number[0] = "zero";    // Unused, but makes it easier to map from int to string
  number[1] = "one";
  number[2] = "two";
  number[3] = "three";
  number[4] = "four";
  number[5] = "five";
  number[6] = "six";
}


(Possibly it would be better practice to use Hungarian notation or a suffix to indicate the data type here, since it's potentially confusing.)

Are you doing that, slasher, and making sure you're actually running initNumbers() ahead of time so the values aren't null?

Slasher

Ok,

i'm going to bite the bullet and get ready for rear buckshots (laugh)

here is all my code it gives string argument is not a string:

Code: ags

//top of room script

bool roll=false;
bool throw=true;

#define SQUARE_COUNT 28
int currentSquare;
int squareX[SQUARE_COUNT];
int squareY[SQUARE_COUNT];



function room_Load()
{
  currentSquare=1;
  gStatusline.Clickable=false;
  cGandolf.Clickable=false;
  cGandolf.Baseline=0;
  cHobbit.Loop=3;
  game.speech_text_align=eAlignLeft;
  oDice.SetView(6);
  oDice.Animate(0, 4, eRepeat, eNoBlock);

} 
  void initBoard()
{
  // From square 1

  squareX[0] = 50; squareY[0] = 470;
  squareX[1] = 50; squareY[1] = 379;
  squareX[2] = 136; squareY[2]=368;
  squareX[3] = 50; squareY[3] = 268;
  squareX[4] = 50; squareY[4] = 173;
  squareX[5] = 136; squareY[5] = 173;
  squareX[6] = 225; squareY[6] = 173;
  squareX[7] = 225; squareY[7] = 255;
  squareX[8] = 314; squareY[8] = 173;
  squareX[9] = 396; squareY[9] = 173;
  squareX[10] = 485; squareY[10] = 173;
  squareX[11] = 575; squareY[11] = 173;
  squareX[12] = 575; squareY[12] = 237; 
  squareX[13] = 658; squareY[13] = 173;
  squareX[14] = 744; squareY[14] = 173;
  squareX[15] = 744; squareY[15] = 265; 
  squareX[16] = 744; squareY[16] = 355;
  squareX[17] = 744; squareY[17] = 254; 
  squareX[18] = 744; squareY[18] = 371; 
  squareX[19] = 672; squareY[19] = 382; 
  squareX[20] = 678; squareY[20] = 457; 
  squareX[21] = 744; squareY[21] = 457; 
  squareX[22] = 586; squareY[22] = 457;
  squareX[23] = 494; squareY[23] = 457; 
  squareX[24] = 494; squareY[24] = 438; 
  squareX[25] = 415; squareY[25] = 457; 
  squareX[26] = 322; squareY[26] = 457;
  squareX[27] = 322; squareY[27] = 376; 
  squareX[28] = 278; squareY[28] = 376; 

}
 void movePlayer(int squaresToMove)
{
 
 currentSquare = (currentSquare + squaresToMove) % SQUARE_COUNT;
 player.Walk(squareX[currentSquare],squareY[currentSquare]);
 }
String number[7];

void initNumbers()
{
  number[0] = "zero";    
  number[1] = "one";
  number[2] = "two";
  number[3] = "three";
  number[4] = "four";
  number[5] = "five";
  number[6] = "six";
}

function oTumbler_Interact()
{
  int dieRoll = Random(5)+1; 

if(roll==false && throw==true){

  oTumbler.SetView(6);
  oTumbler.Animate(1, 1, eRepeat, eNoBlock);
  oDice.SetView(6);
  oDice.Animate(0, 1, eRepeat, eNoBlock);
  roll=true;

} 
 else if(roll==true && throw==true){
 oDice.StopAnimating();
 oTumbler.StopAnimating();
 Wait(10);
 oTumbler.Move(oTumbler.X, oTumbler.Y-40, 2, eBlock, eAnywhere);
 Wait(20);



if(oDice.Frame ==0){
   

 cGandolf.SayAt(cGandolf.x+9, cGandolf.y - 100, 500, String.Format("You have rolled a %s.", number[dieRoll]));
 oTumbler.Move(oTumbler.X, oTumbler.Y+40, 2, eBlock, eAnywhere);
 currentSquare = (currentSquare + oDice.Frame) % SQUARE_COUNT; // you might need to convert oDice.Frame to an integer?
 cHobbit.Walk(squareX[currentSquare], squareY[currentSquare], eBlock, eAnywhere);   
   
// etc etc through all the dice numbers

// It could be to do with the way i use odice frame to add event, possibly.....



Well. there you have it... :-[





Snarky

#23
OK, great. I see a few problems:

-The direct cause of the crash is, I think, that you haven't initialized the number[] array by calling initNumbers(); this is what I asked you in the last post
-You've mixed different versions of the snippets we've given you, with duplication and unused code. This can be simplified
-You're using a different method to roll the die, so you don't need the Random() call.
-You really don't want (or need!) to write six different cases, one for each number on the die. It's very simple to have the same code for all of them, and that's part of what the snippets we gave you were for
-You really need to learn how to indent. By not doing it consistently you create a lot of confusion and possibility of bugs

Here's a cleaned-up, hopefully fixed version of the code:

Code: ags

//top of room script

bool roll=false;
bool throw=true;    // You're never actually setting this value to anything other than true, so it's redundant

#define SQUARE_COUNT 28
int currentSquare;
int squareX[SQUARE_COUNT];
int squareY[SQUARE_COUNT];
String numberString[7];

void initNumbers()
{
  numberString[0] = "zero";    
  numberString[1] = "one";
  numberString[2] = "two";
  numberString[3] = "three";
  numberString[4] = "four";
  numberString[5] = "five";
  numberString[6] = "six";
}

void initBoard()
{
  // From square 1

  squareX[0] = 50; squareY[0] = 470;
  squareX[1] = 50; squareY[1] = 379;
  squareX[2] = 136; squareY[2]=368;
  squareX[3] = 50; squareY[3] = 268;
  squareX[4] = 50; squareY[4] = 173;
  squareX[5] = 136; squareY[5] = 173;
  squareX[6] = 225; squareY[6] = 173;
  squareX[7] = 225; squareY[7] = 255;
  squareX[8] = 314; squareY[8] = 173;
  squareX[9] = 396; squareY[9] = 173;
  squareX[10] = 485; squareY[10] = 173;
  squareX[11] = 575; squareY[11] = 173;
  squareX[12] = 575; squareY[12] = 237; 
  squareX[13] = 658; squareY[13] = 173;
  squareX[14] = 744; squareY[14] = 173;
  squareX[15] = 744; squareY[15] = 265; 
  squareX[16] = 744; squareY[16] = 355;
  squareX[17] = 744; squareY[17] = 254; 
  squareX[18] = 744; squareY[18] = 371; 
  squareX[19] = 672; squareY[19] = 382; 
  squareX[20] = 678; squareY[20] = 457; 
  squareX[21] = 744; squareY[21] = 457; 
  squareX[22] = 586; squareY[22] = 457;
  squareX[23] = 494; squareY[23] = 457; 
  squareX[24] = 494; squareY[24] = 438; 
  squareX[25] = 415; squareY[25] = 457; 
  squareX[26] = 322; squareY[26] = 457;
  squareX[27] = 322; squareY[27] = 376; 
  squareX[28] = 278; squareY[28] = 376; 
}

function room_Load()
{
  initBoard();        // ADDED!
  initNumbers();      // ADDED!
  currentSquare=0;    // CHANGED!
  gStatusline.Clickable=false;
  cGandolf.Clickable=false;
  cGandolf.Baseline=0;
  cHobbit.Loop=3;
  game.speech_text_align=eAlignLeft;
  oDice.SetView(6);
  oDice.Animate(0, 4, eRepeat, eNoBlock);
}

void movePlayer(int squaresToMove)
{
  currentSquare = (currentSquare + squaresToMove) % SQUARE_COUNT;
  cHobbit.Walk(squareX[currentSquare],squareY[currentSquare]);
}

function oTumbler_Interact()
{
  if(roll==false && throw==true)
  {
    oTumbler.SetView(6);
    oTumbler.Animate(1, 1, eRepeat, eNoBlock);
    oDice.SetView(6);
    oDice.Animate(0, 1, eRepeat, eNoBlock);
    roll=true;
  }
  else if(roll==true && throw==true)
  {
    oDice.StopAnimating();
    oTumbler.StopAnimating();
    Wait(10);
    oTumbler.Move(oTumbler.X, oTumbler.Y-40, 2, eBlock, eAnywhere);
    Wait(20);

    cGandolf.SayAt(cGandolf.x+9, cGandolf.y - 100, 500, String.Format("You have rolled a %s.", numberString[oDice.Frame + 1]));
    oTumbler.Move(oTumbler.X, oTumbler.Y+40, 2, eBlock, eAnywhere);
    movePlayer(oDice.Frame + 1);
  }
}


I also feel the need to point out that if this is meant to be a Hobbit game, the name of the wizard is Gandalf, not Gandolf.

Slasher

Cheers Snarky it's almost on the button except re-animating the tumbler, i can do this...

also i need to tweak the initBoard squareX 's and squareY 's.

So, all in all a success (nod)

Oh, yes: Gandalf...

thanks so much Snarky (nod)

back to testing....let you know..

cheers


SMF spam blocked by CleanTalk