DaJAngband hacking: help with the code (please, I wont ask much!)
Collapse
X
-
Yours is just fine. Mine was shorter, but wrong. (I didn't pay attention to the .text in the original.) Use either one, but definitely keep the .text!Leave a comment:
-
Thank you!
For your amusement(?): my new guess would have been:
Code:IF (cp_ptr->spell_book == TV_MAGIC_BOOK) idx = spell; ELSE IF (cp_ptr->spell_book == TV_PRAYER_BOOK) idx = spell + PY_MAX_SPELLS; ELSE idx = spell + (PY_MAX_SPELLS * 2); text_out(s_text + s_info[idx].text);
EDIT: I put your suggestion in, and it's not working. It's giving me a "invalid operands to binary +" error message for the text_out line. I don't know what that means.Last edited by will_asher; March 13, 2008, 05:00.Leave a comment:
-
int idx;
idx = spell;
if (cp_ptr->spell_book == TV_PRAYER) idx += PY_MAX_SPELLS ;
else if(cp_ptr->spell_book == TV_NATURE) idx += 2*PY_MAX_SPELLS;
text_out(s_text + s_info[idx]);
(I used TV_NATURE; you should use whatever the name of your new realm is.)
You can't increment s_info(!) It is a constant global variable, and you will really screw things up.Leave a comment:
-
DaJAngband hacking: help with the code (please, I wont ask much!)
As you probably know from my previous posts, I'm attempting to create a variant while knowing extremely little of the C language. This is possible mainly because of how well the Angband code is organized and commented (thanks again). All I know of the C language is from the tutorial "beej's Guide to C programming" and from looking at the Angband code. (I only read the first few sections of the tutorial thoroughly, but I kindof scanned the rest for the answer to my question and didn't find it.)
I would really like a figure out how to add a new magic realm and I've almost done it. Here's my question:
I can figure out that the following is an either/or statement, but I can't figure out how to turn it into an If/then/elseif statement.
Code:text_out(s_text + s_info[(cp_ptr->spell_book == TV_MAGIC_BOOK) ? spell : spell + PY_MAX_SPELLS].text);
Code:IF (cp_ptr->spell_book == TV_MAGIC_BOOK) s_info = spell; ELSE IF (cp_ptr->spell_book == TV_PRAYER_BOOK) s_info = spell + PY_MAX_SPELLS; ELSE s_info = spell + (PY_MAX_SPELLS * 2);
thanks in advanceTags: None
Leave a comment: