Jump to content

Hal's Great Cave Offensive

Photo

[Resolved] Request: Help with scripting.


  • Please log in to reply
11 replies to this topic

#1 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 05 October 2016 - 01:07 AM

The current issue is resolved. This thread will remain open for further discussion.

 

So it has come to me that I need some help with this quest. And that is, I need help from scripters because I am running into scripting issues that just baffle me and significantly impede progress until they are sorted out. These hiatuses have been the cause of many rustled jimmies much frustration and several hiatuses thus so far.
Anyways, here's this lovely block of code that has an issue for some reason:

const int TILE_BIGMAPTILE_START_BASE = 34980; //The tile corresponding to the tiles containing the pieces of the minimap on the tilesheet
const int TILE_BIGMAPTILE_START_DESTINATION = 34320; //The tile corresponding to the tiles containing the pieces of the minimap on the tilesheet that will be displayed on the subscreen

int mapindex[2] = {1, 2}; //The current number of playable maps (in ZQ terms) in the quest and their map numbers.

int mapdata[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
//The array used for keeping track of states that the map shows. Each element corresponds to a screen on the map. 

const int MAPFLAG_VISITED = 1; //Marks the screen as visited, so the map continues to work after saving.
const int MAPFLAG_ITEM = 2; //Marks the screen as having an unobtained item
const int MAPFLAG_ITEM_TAKEN = 4; //Marks the screen as having an obtained item
const int MAPFLAG_BOSS = 8; //Marks the screen as having a boss on it
const int MAPFLAG_MINECART = 16; //Marks the screen as having a minecart on it.

void MapUpdate(){ //Updates the tiles used for the map.
	if(Link->Action == LA_SCROLLING){ //Update when Link is scrolling
		if(Game->GetCurMap() == mapindex[0] || Game->GetCurMap() == mapindex[1]){ //Link is on the first two maps according to mapindex[]
			CopyTile(TILE_BIGMAPTILE_START_BASE + (Game->GetCurMap()-1)*160 + (Game->GetCurScreen()+(Div(Game->GetCurScreen(), 16)*4)), TILE_BIGMAPTILE_START_DESTINATION + (Game->GetCurMap()-1)*160 + (Game->GetCurScreen()+(Div(Game->GetCurScreen(), 16)*4))); //Copy the map tiles over the "blank" map tiles (that are displayed on the Map screen) when the player goes to the screen 
			mapdata[(Game->GetCurMap()-1)*128 + Game->GetCurScreen()] |= MAPFLAG_VISITED; //Flag the screen as visited, so I can keep the map between saves
		}
	}
}

The issue I am facing here is in this line:

mapdata[(Game->GetCurMap()-1)*128 + Game->GetCurScreen()] |= MAPFLAG_VISITED; //Flag the screen as visited, so I can keep the map between saves

By all forms of logic, this line should be setting the MAPFLAG_VISITED flag to the correct element. However it is not, leaving that element at 0. I've ran traces to confirm that the flag is not being set at all and that it is not being set to the wrong element.

Can anyone explain what is going wrong here?

 

 

Edit: Issue resolved.


Edited by Orithan, 10 October 2016 - 05:09 AM.


#2 grayswandir

grayswandir

    semi-genius

  • Members

Posted 05 October 2016 - 02:02 AM

The LA_SCROLLING check seems suspicious. Are you scrolling onto the screen you're checking? Because walking out of a cave or teleporting in won't trigger that.

 

My first guess is that the line in question isn't even being run. Have you confirmed that the code is actually being run? Is the tile being copied?

Generally, for this situation, I'd also trace out:

- The (Game->GetCurMap()-1)*128 + Game->GetCurScreen()] calculation to make sure it is correct.

- The value of the variable in question immediately before AND immediately after setting it.

 

There's also the possibility that it's actually being set, but later code accidentally unsets it for some reason. Where exactly did you place your traces?



#3 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 05 October 2016 - 03:43 AM

The LA_SCROLLING check seems suspicious. Are you scrolling onto the screen you're checking? Because walking out of a cave or teleporting in won't trigger that.

I am aware that is the case. For the purposes of getting the concept down, I haven't needed to test for walking out of a cave or teleporting yet because the quest hasn't needed to do it yet. But if I do submit any part of the map to the database, I will be sure to make it so that it works with that too.
 

My first guess is that the line in question isn't even being run. Have you confirmed that the code is actually being run? Is the tile being copied?
Generally, for this situation, I'd also trace out:
- The (Game->GetCurMap()-1)*128 + Game->GetCurScreen()] calculation to make sure it is correct.
- The value of the variable in question immediately before AND immediately after setting it.

Through tracing, I confirmed that the code is actually being run and that it copies the tile properly. I can also tell that it is being calculated properly.
 

There's also the possibility that it's actually being set, but later code accidentally unsets it for some reason. Where exactly did you place your traces?

Directly before and after the variable is supposed to be set. I can tell that it is not being set.


Edited by Orithan, 05 October 2016 - 03:51 AM.


#4 Jamian

Jamian

    ZC enthusiast

  • Members

Posted 05 October 2016 - 04:55 AM

Could be that Link is still considered to be on the old screen as you begin scrolling? Try waiting a few frames after the scrolling action is detected. Or better yet (and this would also solve the cave/teleporter issue), store the current location in a variable, and update the map as soon as the most recent current location != the stored location.



#5 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 05 October 2016 - 05:18 AM

Link is considered to be on the new screen on all scrolling frames

#6 Saffith

Saffith

    IPv7 user

  • Members

Posted 05 October 2016 - 08:44 AM

Did you start a new save after adding this? If you reused an existing save, that array doesn't even exist. Do you have the script error logging rule enabled?

#7 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 05 October 2016 - 02:27 PM

Yes to both: It is all being tested in fresh saves and I have the script error logging rule on. The elements array gets written to in another script, but I can't see anything in this other script that stops it from being set here.



#8 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 06 October 2016 - 10:32 AM

What does |= do? Should it be = instead?

 

Sorry, I'm not much of a help here. Maybe you could use the actual screen state ST_VISITED, which you can check globally with GetScreenState and SetScreenState.


Edited by Avataro, 06 October 2016 - 10:35 AM.


#9 Saffith

Saffith

    IPv7 user

  • Members

Posted 06 October 2016 - 11:32 AM

Try changing different factors one at a time. Try writing to, say, mapdata[73] rather than calculating the index. Create another array and see if that one works. Try doing the same thing somewhere else in the script. And if none of that turns anything up, try just rewriting the same thing a bit differently.
 

What does |= do?

Bitwise OR assignment. a|=b ORs a and b together and stores the result in a.

#10 vaualbus

vaualbus

    Junior

  • Members
  • Real Name:Alberto
  • Location:Turin, Italy

Posted 08 October 2016 - 05:38 PM

What does |= do? Should it be = instead?

 

Sorry, I'm not much of a help here. Maybe you could use the actual screen state ST_VISITED, which you can check globally with GetScreenState and SetScreenState.

just a logic or to the bit



#11 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 10 October 2016 - 04:21 AM

Well, I've fixed the issue I was having and the function works perfectly. The problem? Game->GetCurScreen() (and several other functions eg Game->GetScreenD(), Screen->LayerMap(), Game->GetCurDMap() and similar functions to Game->GetCurScreen) do not like to play nice with arrays.
 
Pointing to an element of an array using any of the aforementioned functions directly does not let me write to it for some reason, despite them tracing values that should let it point to a valid element of the array. The game doesn't print script errors to Allegro.log in this case, even when the appropriate quest rule is checked.
 
The workaround is to create and use the function to write to a standalone variable and then use that variable to point to the element of the array.
 
Example of this:
 

//The following code does not work. The array will not be written to in this case.
int myarr[256];
myarr[Game->GetCurScreen()] |= 1;
 
//However, the following code does work. The array will be written to in this case.
int myarr[256];
int myvar = Game->GetCurScreen();
myarr[myvar] |= 1;

Edit: FYI, I will be leaving this thread open in case I run into another blockade.


Edited by Orithan, 10 October 2016 - 04:36 AM.


#12 Saffith

Saffith

    IPv7 user

  • Members

Posted 10 October 2016 - 12:18 PM

Oh, hell. That's a compiler error. It stores the value to write in d5, then the function call clobbers it for no obvious reason. This'll be fun to fix.

Edit: I think I've got it worked out. There'll be a 2.50.3 RC soonish. Try it out again there, would you?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users