Jump to content
  • 0
Sign in to follow this  
bWolfie

Issue reading custom state in plugin

Question

Hello, I am trying to create a piece of code using a plugin which will return 0;

I started by creating my struct player_data, which contain state my_state, intended to be set and red as ssd->state.my_state (1st code box)

I set my_state using an atcommand and it seems to set ok. But when I'm trying to bring it up in the following code (2nd code box), ssd->state.my_state is returning 0 even though I am sure it is really set to 1 after using my atcommand.

Looking for help thank you.

struct player_data {
	struct {
		unsigned short my_state : 1;
	} state;
}
if (target && target->type == BL_PC) {
	struct map_session_data *sd = BL_CAST(BL_PC, target);
	if (sd) {
		struct player_data *ssd;
		if (!(ssd = getFromMSD(sd, 0))) {
			CREATE(ssd, struct player_data, 1);
			addToMSD(sd, ssd, 0, true);
		}
		if (ssd && ssd->state.my_state == 1)
			return 0;
	}
}

 

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

if my_state == 1 you returning 0, but you said you want return 1

if you mean what my_state is not 1, try to check is you really save it correct in atcommand. after save in same command, read it back and check.

 

Share this post


Link to post
Share on other sites
  • 0

This is my atcommand. I thought it was working since the clif->message is displaying correct message when I use it.

// @my_state - sets state.my_state
ACMD(my_state)
{
	struct player_data *ssd;
	if ((ssd = getFromMSD(sd, 0)) == NULL) {
		CREATE(ssd, struct player_data, 1);
		addToMSD(sd, ssd, 0, true);
	}

	ssd->state.my_state = !ssd->state.my_state;
	clif->message(fd, msg_fd(fd, (ssd->state.my_state) ? 1553: 1554));  // my_state mode [enabled/disabled].

	return true;
}

 

When I mean return 0, I mean function is returning 0. It's not relevant to issue.
ssd->state.my_state should return 1 after using my atcommand, but it's always returning 0 (I tested using ShowDebug("%d", ssd->state.my_state); in my 2nd code box)

Edit: I tested by returning each ssd, and it seems they are not the same ssd?
I.e. the ssd in the @my_state command is not the same as the one in my function.

Edited by Myriad

Share this post


Link to post
Share on other sites
  • 0

I can only retry what i said before

Quote

try to check is you really save it correct in atcommand. after save in same command, read it back and check.

 

Share this post


Link to post
Share on other sites
  • 0

Yup the atcommand is setting it correctly.

But when I use it in my function, it is not checking the same ssd.

That is, the ssd are not the same.
Imagine atcommand is using sd 1111 and ssd 1234
But function is using sd 1111 and ssd 1235.

Share this post


Link to post
Share on other sites
  • 0

I mean check in one function is it works in correct way. at first call addToMSD, set your flag, then getFromMSD, and check your flag

All this in one function

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...
Sign in to follow this  

×
×
  • Create New...

Important Information

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