Jump to content
  • 0

How to call const in libconfig


Question

Posted (edited)

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

4 answers to this question

Recommended Posts

Posted

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);
			...
...
Posted

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;
			}
		}
	}
Posted (edited)
...
			...
			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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...