basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 04:48
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Basic Coding
| |-+  General Basic Programming
| | |-+  Q&A
| | | |-+  Yabasic - Calculations.
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Reply Print
Author Topic: Yabasic - Calculations.  (Read 285 times)
Mainchip
Guest
« on: Mar 22. 2008, 07:44 » Reply with quote

Hi all,

How would I go about doing this...

Code:
mob-life = 100
strength = 5
mob-def = 2
damage = strength - mob-def * 2

I need to work out the damage so I want yabasic to do some calculations:

5 - 2 = 3 * 2 = 6

Thank you,
Mainchip.
Report to moderator   Logged
PetrSchreiber
Full Member
***
Offline Offline

Posts: 100


WWW
« Reply #1 on: Mar 22. 2008, 09:45 » Reply with quote

Hi Mainchip,

I am not an expert on Yabasic, but here little help:
  • do not use "-" in variables, use underscore "_" instead
  • respect operator precedence, or when not sure use brackets

So your code could be:
Code:
mob_life = 100
strength = 5
mob_def = 2
damage = ( strength - mob_def ) * 2

As "*" has higher priority than "+" or "-" then you have to use brackets to get the result 6
(evaluated as (5-2)*2 = 6 ).

Your:
Code:
damage = strength - mob_def * 2
would be evaluated as 5 - ( 2 * 2 ).


Bye,
Petr
« Last Edit: Mar 22. 2008, 09:48 by PetrSchreiber » Report to moderator   Logged

Mainchip
Guest
« Reply #2 on: Mar 22. 2008, 09:55 » Reply with quote

Thank you,

A quick reply as well, I see what I was doing wrong. Silly mistake lol

Thank you,
Mainchip.
Report to moderator   Logged
Mainchip
Guest
« Reply #3 on: Mar 22. 2008, 10:25 » Reply with quote

I have another problem,

Using repeat and until, example

Code:
repeat
code here
until (eg1)

How can I keep repeating until either (eg1) requirements met or (eg2).

So it will end if eg1 meets requirements or end if (eg2) meets requirements.

Sorry if it doesn't make sense I did not know how to explain it.

Thank you,
Mainchip.
Report to moderator   Logged
Derek
Administrator
Hero Member
*****
Online Online

Posts: 1001



WWW
« Reply #4 on: Mar 22. 2008, 10:30 » Reply with quote

I have another problem,

Using repeat and until, example

Code:
repeat
code here
until (eg1)

How can I keep repeating until either (eg1) requirements met or (eg2).

So it will end if eg1 meets requirements or end if (eg2) meets requirements.

Sorry if it doesn't make sense I did not know how to explain it.

Thank you,
Mainchip.

I think you mean that you need something like this:
Code:
repeat
   // Do stuff
until(eg1 or eg2)
the conditions in while/wend or repeat/until loops can use "and", "or", "not" etc just like in if/then conditions.

Derek.
Report to moderator   Logged

wget http://*
Mainchip
Guest
« Reply #5 on: Mar 22. 2008, 10:32 » Reply with quote

Yes, that is it I couldn't figure it out I put this:

Code:
until (eg1) or (eg2)

I put 'or' outside the brackets.

Thank you,
Mainchip.
Report to moderator   Logged
Pages: [1] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!