DaJAngband hacking: help with the code (please, I wont ask much!)

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • will_asher
    replied
    oh.. okay. thanks again.

    Leave a comment:


  • Pete Mack
    replied
    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:


  • will_asher
    replied
    Thank you!


    Originally posted by Pete Mack
    You can't increment s_info(!) It is a constant global variable, and you will really screw things up.
    That much I figured out after another minute of looking at the code. I was right about to edit my message with a new guess when I saw your post.
    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);
    I probably would have remembered to add the "int idx;" part later, but I still wouldn't have gotten it right. I would never have known to take the ".text" part out.

    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:


  • Pete Mack
    replied
    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);
    I would guess I would do something like
    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);
    Obviously, I'm not sure this is right, and even if I was, I wouldn't know how to do the text_out() part. Can someone help me with this please?

    thanks in advance
Working...
😀
😂
🥰
😘
🤢
😎
😞
😡
👍
👎