IGNORED

# on x gosub into a loop

## Recommended Posts

Quote
enemy_ia
for i = 0 to 7
a = enemy_state
on a gosub _egg, _hatch, _born
next.
return
_egg
return
_hatch
return
_born
return

How can I make this work?, I have also tried with on ... goto and then jump before the next but it doesn't work.

Thanks

##### Share on other sites

This way I get no errors

Quote
enemy_ia
for i = 0 to 7
a = rand;enemy_state
if a = 0 then gosub _egg : goto _loop_ia
if a = 1 then gosub _hatch : goto _loop_ia
if a = 3 then gosub _born : goto _loop_ia
; on a goto _egg, _hatch, _born
_loop_ia
next
return
_egg
return
_hatch
return
_born
return

##### Share on other sites

In your first example is the (.) after next in your source code?

##### Share on other sites

16 minutes ago, CloakeD said:

In your first example is the (.) after next in your source code?

No, it was a typo

Also, why this doesn't work?

`  if yenemy[i] = 16*8 then enemy_state[i] = STATE_MOVE`

but this works

```  a = yenemy[i]
if a = 16*8 then enemy_state[i] = STATE_MOVE```

##### Share on other sites

2 hours ago, swapd0 said:

How can I make this work?, I have also tried with on ... goto and then jump before the next but it doesn't work.

Thanks

you have a comma after each goto destination

Try something like :

` on a gosub _egg _hatch _born`

##### Share on other sites

49 minutes ago, swapd0 said:

No, it was a typo

Also, why this doesn't work?

```
if yenemy[i] = 16*8 then enemy_state[i] = STATE_MOVE```

but this works

```
a = yenemy[i]
if a = 16*8 then enemy_state[i] = STATE_MOVE```

I'm not 100% sure here, but I think 7800Basic can't test an array value directly against an array value so you need to load your first value into a temp variable, which you have done in the second example. (more or less - There might be a more technical explanation but that's how I understand it).

##### Share on other sites

7 minutes ago, Muddyfunster said:

you have a comma after each goto destination

Try something like :

```
on a gosub _egg _hatch _born```

It works, lol I looked at the docs many times but I didn't realized about the comma XD

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.