Jump to content
  • 0
andybe

mapreg->setreg question

Question

hi, I'm currently reviewing battleground.c

but I'm stuck at this part of the code.

for (i = 0; i < VECTOR_LENGTH(queue->entries); i++) {
			struct map_session_data *sd = map->id2sd(VECTOR_INDEX(queue->entries, i));

			if (sd == NULL || sd->bg_queue.ready != 1)
				continue;
			int uid = reference_uid(script->add_str("$@bg_member"), count);
#ifdef TRACE
			ShowXilero("BG begin uid $@bg_member %d\n", uid);
#endif

			mapreg->setreg(uid, sd->status.account_id);
			mapreg->setreg(reference_uid(script->add_str("$@bg_member_group"), count),
			               sd->bg_queue.type == BGQT_GUILD ? sd->status.guild_id :
			               sd->bg_queue.type == BGQT_PARTY ? sd->status.party_id :
			               0
			               );
			mapreg->setreg(reference_uid(script->add_str("$@bg_member_type"), count),
			               sd->bg_queue.type == BGQT_GUILD ? 1 :
			               sd->bg_queue.type == BGQT_PARTY ? 2 :
			               0
			               );
			count++;
		}
		mapreg->setreg(script->add_str("$@bg_member_size"),count);


 

particularly

mapreg->setreg(reference_uid(script->add_str("$@bg_member"), count), sd->status.account_id);

i pieced that up to debug what is happening.

I noticed that they all adress the same variable with the same uid, thus the data is overwriting each other in each loop. SO all the individual playerdata is lost. It feels to me like that is not intentional and neither going to work out well.

I placed this in scripting topic as using mapreg is obviously relevant to scripting.

This directly leads to the question how to best adress to that variable in script. Is there a way to create an array with mapreg->setreg? that way we can iterate through the arrays and process the data accordingly for each member of the queue

 

thanks if anyone can clear that up for me

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

It's not getting overwritten; reference_uid() is var, index. In this case "count" is the index, and it's being incremented every time (count++).

 

To iterate through those variables in script, a simple for() loop will do the trick just fine. See also:

 

Share this post


Link to post
Share on other sites
  • 0

I see - I might be running a little off topic but how come uid turns out the same for different count values in my debug screen?

cause I forgot to declare it as int64?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.