Is there a *gosubref command?


#1

I’ve been able to link

*temp rootword
*temp affix
*temp get_ai
*set rootword enemy_class
*set affix “_ai”
*set get_ai rootword&affix
*gotoref get_ai

and this delivers me to, for example, goblin_ai or orc_ai depending on the enemy_class. With this, it was possible at last to get enemies that behave conspicuously differently. Now my problem is that it punts my nicely nested chain of *gosub commands out of the combat report.

Then the goblin_ai contains something like

*rand ai_select 1 4

*if ai_select = 1
*set action_id 101
*if ai_select = 2
*set action_id 102

*return

then back to the combat script

*gosub execute_action

*if action_id = 101
*gosub action_101

*label action_101
*comment – simple_attack
[… etc]
*return

*label action_102
*comment – simple_attack
[… etc]
*return

… then that goes back to complete the combat report.

Being able to *gosub combat_script from anywhere in the story progression sounded like a time-saver at the start, but now I’m not so sure. I solved this partially via *goto continue_combat, but it seems rather clunky to have to do this each time for each executed action.


#2

I’m failing to see what your problem is? *gotoref is quite powerful, but it’s applications are different to *gosub.

You don’t really want to dynamically call subroutines, that can get messy and very hard to debug.

Use *gotoref for dynamic/flexible code and use *gosub for SPECIFIC, PREDICTABLE functions.

Edit: Have you checked out the wiki articles covering concatenation, gosub and gotoref/setref? There’s a lot of useful information there and plenty of good examples, I’ve also posted a system or two based upon *gotoref commands. They may be of some help.


#3

My problem is laziness. :stuck_out_tongue:

Since gotoref is basically a goto, I need another goto out of the chunk. The combat system I’m using is inspired by RPGMaker and its lists of characters, actions, and items. So there’s a lot to manually go through and add again -

*if active_player = “hero”
*goto continue_hero_turn
*if active_player = “enemy”
*goto continue_enemy_turn

… instead of just one *return at the end

Not really any real issue, but just curious if I was missing something.


#4

It’s kind of hard for me to wrap my head around what you’re trying to do with small snippets of code, and I’m unfamiliar with RPGMaker - Could you write out a process tree? There may be a more efficient way to do it; I just can’t quite grasp the point of concept (idea) at this point.


#5

Mind I do this a bit later in a new thread?

I’m almost done with the demo, needing to strip out practically every gosub and replace them with goto.


#6

Sure, doesn’t bother me either way.
I wasn’t trying to suggest you shouldn’t use *gosub though, far from it. You just have to use the right one (*gosub / *goto(ref) ) at the right time.


#7

Just a quick FYI: Use `

` before your code and `

` after it to preserve indentation or < code> to just highlight things.


#8

offtopic: how to I insert images here? I seem to recall seeing an image showing up like the embed of a forum around here somewhere.

Does < code > run as unrestricted html?


#9

If you can, try to just link to images. It saves bandwidth for those of us that have little.

You see how `

` is highlighted? That's what code does. `

does the same thing but preserves indentation (``` doesn't), so you should use it for posting snippets of CS code. However, ``` shows HTML (while

` does not).

As for HTML, the forums allows some limited uses, just insert the code directly into the post. I know <a href = "http://www.w3schools.com/tags/att_a_href.asp">href</a> works, I'd imagine that <a href = "http://www.w3schools.com/tags/tag_img.asp">img</a> works too, but I've never bother with it, and, as I said before, it'd be polite to just link.

For example, here's that last paragraph (broken up) displayed via ```:

`As for HTML, the forums allows some limited uses, just insert the code directly
into the post. I know <a href = "http://www.w3schools.com/tags/att_a_href.asp">href</a>
works, I'd imagine that <a href = "http://www.w3schools.com/tags/tag_img.asp">img</a> works
too, but I've never bother with it, and, as I said before, it'd be polite to just link.`

#10

<img src="http://www.website.com/images/file.png"/>
Is how you’d do it.