Jump to content
  • 0
misterM

How to call const in libconfig

Question

Well I need to do a check using libconfig, I'm creating a custom conf file.

{
	NPC = "Name const"
	Effect = Name const
}
if (!config_setting_lookup_string(rs, "Name", &var) {
         ShowWarning("NPC: NPC name '%s' unknown\n", name);
         continue;
}

How can I make to the NPC and Effect option check if name exists in the const

Edited by misterM
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

use

...
int n = 0;
if (!script_get_constant(var, &n))
    // const value not found
...
 

Hello Cydh, I had tried to do this before, but it didn't work out, always shows that npceffect was not found in const. that's why I said this above^^^^

npceffect: (
{
	NPC = "4_M_ORIENT01"
	Effect = "EF_SC_ESCAPE"
}
)
npceff = config_lookup(&npceffect_conf, "npceffect");

	if (npceff != NULL) {
		while ((npcef = config_setting_get_elem(npceffect_conf.root, i++))) {
			const char *namevar = config_setting_name(npcef);

			if (!config_setting_lookup_string(npcef, "NPC", &var)) {
					ShowWarning("npceffect_conf: NPC name '%s' unknown.\n", namevar);
					continue;
			}

			if (!config_setting_lookup_string(npcef, "Effect", &var)) {
				ShowWarning("npceffect_conf: Effect '%s' unknown.\n", namevar);
				continue;
			}
		}
	}

...
			...
			int eff_id = -1;
			...
			if (config_setting_lookup_string(npcef, "Effect", &var))
				script_get_constant(var, &eff_id);

			if (eff_id == -1) {
				ShowWarning("npceffect_conf: Effect '%s' unknown.\n", var);
				continue;
			}
			else
				ShowInfo("npceffect_conf: Effect '%d'\n", eff_id);
			...
...
Link to comment
Share on other sites

use

...
int n = 0;
if (!script_get_constant(var, &n))
    // const value not found
...

 

Hello Cydh, I had tried to do this before, but it didn't work out, always shows that npceffect was not found in const.

npceffect: (
{
	NPC = "4_M_ORIENT01"
	Effect = "EF_SC_ESCAPE"
}
)
npceff = config_lookup(&npceffect_conf, "npceffect");

	if (npceff != NULL) {
		while ((npcef = config_setting_get_elem(npceffect_conf.root, i++))) {
			const char *namevar = config_setting_name(npcef);

			if (!config_setting_lookup_string(npcef, "NPC", &var)) {
					ShowWarning("npceffect_conf: NPC name '%s' unknown.\n", namevar);
					continue;
			}

			if (!config_setting_lookup_string(npcef, "Effect", &var)) {
				ShowWarning("npceffect_conf: Effect '%s' unknown.\n", namevar);
				continue;
			}
		}
	}
Link to comment
Share on other sites

...
			...
			int eff_id = -1;
			...
			if (config_setting_lookup_string(npcef, "Effect", &var))
				script_get_constant(var, &eff_id);

			if (eff_id == -1) {
				ShowWarning("npceffect_conf: Effect '%s' unknown.\n", var);
				continue;
			}
			else
				ShowInfo("npceffect_conf: Effect '%d'\n", eff_id);
			...
...

 

 

Thanks Cydh is working.

Edited by misterM
Link to comment
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.   Paste as plain text instead

  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.



×
×
  • Create New...

Important Information

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