Yiv 321 Posted July 3, 2014 Share Posted July 3, 2014 Dear community, I wanted to give myself the option with expanding to an international server, so I want to script my quests multilingualable. For this, I wrote a function lang.get_text(string) which searches in a table for the entry and returns the text in the language the user has chosen. Everything's fine but if I try this: when npc_list.BIOLOGIST.chat.lang.get_text("test_quest_chat") begin The compiler arborts with this: SHLVL=1:25:when doesn't have begin-end clause. (lang) Abort trap (core dumped) Someone may help me? Regards Link to comment Share on other sites More sharing options...
Developer PACI 921 Posted July 3, 2014 Developer Share Posted July 3, 2014 It's not possible to use functiones on that kind of things, e.g: when XXXXX.chat.text[pc.getf("lang", "lang")][1] begin The better way (and I guess the unique) to do that is using click event instead of chat. But now with the source I guess all it's possible. when you return 0 and server doesn't boot: Link to comment Share on other sites More sharing options...
Think 117 Posted July 4, 2014 Share Posted July 4, 2014 You can allow for functions or variables on chat by tweaking the qc.cc file - Did it first day with source to allow precisely that. Fair warning, though. As with any parser, at first it's confusing to look at the source xD You want to change before here: current_when_argument += os.str(); And what I did was implement a recursive check for parenthesis to allow arguments on said function call (The parenthesis for the func call are the only real problem that needs to be changed). It's not very tested since we didn't end up using it, but I can confirm that my initial tests worked, compiled and displayed ingame. This is what I added if I recall correctly: //Accept functions as valid arguments const char TK_OPEN_PARENTHESIS = '(', TK_CLOSE_PARENTHESIS = ')'; if (lexstate.lookahead.token == TK_OPEN_PARENTHESIS) { int depth = 0; while(lexstate.lookahead.token != TK_CLOSE_PARENTHESIS || depth > 1) { if(lexstate.lookahead.token == TK_OPEN_PARENTHESIS) //allow function calls inside as well depth++; else if(lexstate.lookahead.token == TK_CLOSE_PARENTHESIS) depth--; next(&lexstate); t = lexstate.t; os << t; lookahead(&lexstate); } os << TK_CLOSE_PARENTHESIS; lookahead(&lexstate); } May require another change somewhere, but doesn't look like it atm. I don't really remember the original state of the file so I can't say for sure. 1 2 Link to comment Share on other sites More sharing options...
Active Member Dex 521 Posted January 28, 2023 Active Member Share Posted January 28, 2023 Hello fellas, the code pasted below works perfectly with pretty much all functions beside the when function itself. I was wondering if someone can share the code or already have a solution for parsing the array in the when function. Here is the code which occurs the error mentioned on the topic. case ST_WHEN_WITH_OR_BEGIN: { assert(nested==2); current_when_condition = ""; if (t.token == TK_WITH) { // here comes Á¶°Ç½Ä next(&lexstate); ostringstream os; os << (lexstate.t); //cout << (lexstate.t); next(&lexstate); while (lexstate.t.token!=TK_DO) { os << " " <<(lexstate.t); //cout << TK_DO<<lexstate.t.token << " " <<(lexstate.t) <<endl; next(&lexstate); } current_when_condition = os.str(); check_syntax("if "+current_when_condition+" then end", current_state_name+current_when_condition); cout << "\twith "; cout << current_when_condition; cout << endl; t = lexstate.t; } if (t.token == TK_DO) { ps = ST_WHEN_BODY; nested++; } else { //error("when doesn't have begin-end clause."); ostringstream os; os << "when doesn't have begin-end clause. (" << t << ")"; error(os.str().c_str()); } } break; The switch case always return the else condition, does anyone have the missing parser code ? Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now