• Hi, I am an utter newbie to basic programming and am kind of stumbling around here. If anyone has the time, I have the problem. I am trying to write a simple
Message 1 of 7 , May 21, 2002
View Source
• 0 Attachment
Hi,

I am an utter newbie to basic programming and am kind of stumbling around
here. If anyone has the time, I have the problem.
I am trying to write a simple character generator for an old rp game.
My program will do what it is supposed to the first repetition, but any
subsequent rolls give me the same results for random powers generation.

Its kinda clunky, forgive me.

STRENGTH = int(rnd(1)*13) + 6
ENDURANCE = int(rnd(1)*13) + 6
AGILITY = int(rnd(1)*13) + 6
INTELLIGENCE = int(rnd(1)*13) + 6
WILLPOWER = int(rnd(1)*13) + 6
CHARISMA = int(rnd(1)*13) + 6
POWSLOTS = int(rnd(1)*5) + 4
FOR A = 1 TO POWSLOTS its seems like it is skipping
POWCOUNT = POWCOUNT + 1 this FOR/NEXT loop
ORIGIN = int(rnd(1)*5) + 1
IF ORIGIN = 1 THEN GOSUB [POWTAB]
IF ORIGIN = 2 THEN GOSUB [DEVTAB]
IF ORIGIN = 3 THEN GOSUB [MPITEMTAB]
IF ORIGIN = 4 THEN GOSUB [SKILLTAB]
IF ORIGIN = 5 THEN GOSUB [MPTAB]
NEXT A
GOSUB [WEAKNESS]
GOTO [QUICKDISPLAY]

thanks for any help anyone can give me

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
• All of this code looks pretty sound to me. The problem may be in one of your Gosubs. Are you reusing A in them? Are you returning from each one of them?
Message 2 of 7 , May 21, 2002
View Source
• 0 Attachment
All of this code looks pretty sound to me. The problem may be in one of
your Gosubs. Are you reusing A in them? Are you returning from each one of
them? Are you returning from the Gosub [weakness] also? Problems with not
interating a for/next loop are usually caused by exiting a for/next loop
prematurly, or failing to return from a gosub and leaving invalid values on
the internal stack the LB uses to keep track of where to go next.

Perhaps if the sugestions above do not help, you might consider sending all
of you code.

Sr. Analyst - ADS Product Tracking MES Applications
Weyerhaeuser Company
Voice : (541) 756-9481
Fax: (541) 756-7612

> ----------
> From: David Hurley[SMTP:uberdave4@...]
> Sent: Tuesday, May 21, 2002 4:39 AM
> To: libertybasic@yahoogroups.com
> Subject: [libertybasic] newbie problem
>
>
> Hi,
>
> I am an utter newbie to basic programming and am kind of stumbling around
> here. If anyone has the time, I have the problem.
> I am trying to write a simple character generator for an old rp game.
> My program will do what it is supposed to the first repetition, but any
> subsequent rolls give me the same results for random powers generation.
>
> Its kinda clunky, forgive me.
>
> STRENGTH = int(rnd(1)*13) + 6
> ENDURANCE = int(rnd(1)*13) + 6
> AGILITY = int(rnd(1)*13) + 6
> INTELLIGENCE = int(rnd(1)*13) + 6
> WILLPOWER = int(rnd(1)*13) + 6
> CHARISMA = int(rnd(1)*13) + 6
> POWSLOTS = int(rnd(1)*5) + 4
> FOR A = 1 TO POWSLOTS its seems like it is skipping
> POWCOUNT = POWCOUNT + 1 this FOR/NEXT loop
> ORIGIN = int(rnd(1)*5) + 1
> IF ORIGIN = 1 THEN GOSUB [POWTAB]
> IF ORIGIN = 2 THEN GOSUB [DEVTAB]
> IF ORIGIN = 3 THEN GOSUB [MPITEMTAB]
> IF ORIGIN = 4 THEN GOSUB [SKILLTAB]
> IF ORIGIN = 5 THEN GOSUB [MPTAB]
> NEXT A
> GOSUB [WEAKNESS]
> GOTO [QUICKDISPLAY]
>
>
> thanks for any help anyone can give me
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
>
> To unsubscribe from this group, send an email to:
> libertybasic-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
• At 05:39 AM 5/21/02 -0600, you wrote:
Message 3 of 7 , May 21, 2002
View Source
• 0 Attachment
At 05:39 AM 5/21/02 -0600, you wrote:
<<My program will do what it is supposed to the first repetition, but any
subsequent rolls give me the same results for random powers generation.>>

It might help to have more of your code. Have you tried using the
debugger? Choose the "step" button and step through your program. Check
the value of each variable as each step is performed and see where it goes
wonky.

I see a potential problem in your loop:

FOR A = 1 TO POWSLOTS its seems like it is skipping
POWCOUNT = POWCOUNT + 1 this FOR/NEXT loop
ORIGIN = int(rnd(1)*5) + 1
IF ORIGIN = 1 THEN GOSUB [POWTAB]
IF ORIGIN = 2 THEN GOSUB [DEVTAB]
IF ORIGIN = 3 THEN GOSUB [MPITEMTAB]
IF ORIGIN = 4 THEN GOSUB [SKILLTAB]
IF ORIGIN = 5 THEN GOSUB [MPTAB]
NEXT A

You have a variable called POWCOUNT which is incremented on each iteration
of your loop. I don't see anyplace in your code where it is zeroed out
before the loop runs, so subsequent activation of your loop will simply
continue to increment that variable. Is this what you want?

Sorry I couldn't offer more concrete assistance.

- Alyce
• Hi, I am a newbie and need some help. I defined a function say randomize() which yields after several calls the correct result.It seems obvious to use a loop
Message 4 of 7 , Mar 1 4:16 AM
View Source
• 0 Attachment
Hi,
I am a newbie and need some help. I defined a function say randomize()
which yields after several calls the correct result.It seems obvious to
use a loop to substitute the calls "by hand". To my surprise this
doesn't work. The loop repeats always the same, i.e there are no
alternative results.If you understand what I mean it would be nice to
kind regards
V.Vanoni
• It would help to see your code. Zack ... [Non-text portions of this message have been removed]
Message 5 of 7 , Mar 1 6:19 AM
View Source
• 0 Attachment
It would help to see your code.

Zack

On 3/1/07, akron_phillies <akron_phillies@...> wrote:
>
> Hi,
> I am a newbie and need some help. I defined a function say randomize()
> which yields after several calls the correct result.It seems obvious to
> use a loop to substitute the calls "by hand". To my surprise this
> doesn't work. The loop repeats always the same, i.e there are no
> alternative results.If you understand what I mean it would be nice to
> kind regards
> V.Vanoni
>
>
>

[Non-text portions of this message have been removed]
• Why am I not surprised? The help file says: RANDOMIZE n Description: This function seeds the random number generator in a predictable way. The seed numbers
Message 6 of 7 , Mar 1 6:38 AM
View Source
• 0 Attachment
Why am I not surprised? The help file says:

RANDOMIZE n

Description:
This function seeds the random number generator in a predictable way. The seed numbers must be greater than 0 and less than 1. Numbers such as 0.01 and 0.95 are used with RANDOMIZE.

Usage:

'this will always produce the same 10 numbers
randomize 0.5
for x = 1 to 10
print int(rnd(1)*100)
next x

LB includes the RND() function to generate numbers. You want a code similar to:
[code]
FOR k=1 TO 10 'The number of random numbers to generate
x=INT(RND(0)*100)+1 'The range of numbers (1-100)
PRINT x
NEXT k

END
[/code]

[Non-text portions of this message have been removed]
• If you have already defined a function that works and you are trying to inline that function (put the code within the function into the main program loop),
Message 7 of 7 , Mar 1 7:42 AM
View Source
• 0 Attachment
If you have already defined a function that "works" and you are trying
to "inline" that function (put the code within the function into the
main program loop), you need to remember that all "local" variables
(variables not used outside of the function) are set to zero each time
you call that function. You must set those variables to zero when
you "inline" the function, then you will get the expected results.

If that's not what you are doing, then definitely post some code and

Andy

--- In libertybasic@yahoogroups.com, "akron_phillies"
<akron_phillies@...> wrote:
>
> Hi,
> I am a newbie and need some help. I defined a function say randomize()
> which yields after several calls the correct result.It seems obvious
to
> use a loop to substitute the calls "by hand". To my surprise this
> doesn't work. The loop repeats always the same, i.e there are no
> alternative results.If you understand what I mean it would be nice
to
> kind regards
> V.Vanoni
>
Your message has been successfully submitted and would be delivered to recipients shortly.