misterM Posted February 16, 2015 Posted February 16, 2015 (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 February 16, 2015 by misterM Quote
Cydh Posted February 16, 2015 Posted February 16, 2015 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); ... ... Quote
Cydh Posted February 16, 2015 Posted February 16, 2015 use ... int n = 0; if (!script_get_constant(var, &n)) // const value not found ... Quote
misterM Posted February 16, 2015 Author Posted February 16, 2015 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; } } } Quote
misterM Posted February 16, 2015 Author Posted February 16, 2015 (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 February 17, 2015 by misterM Quote
Question
misterM
Well I need to do a check using libconfig, I'm creating a custom conf file.
How can I make to the NPC and Effect option check if name exists in the const
Edited by misterM4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.