Need a Parachute Calculator?

Discussion about deployment systems including altimeters, timers, air speed flaps, servo systems, and chemical reactions.
RebelRockets
Advanced Member
Advanced Member
Posts: 54
Joined: Tue Sep 08, 2009 9:51 pm

Re: Need a Parachute Calculator?

Post by RebelRockets »

Here is a sample of the code, taken from the button where you enter the weight in grams. Keep in mind this is from version 6, the syntax may have changed slightly in newer versions.
I've marked the code for the pop-up boxes. As an equation just 1+2 would create an error. You need a variable and '=', such as answer = 1 + 2;. Read the 'variables' section in the help files carefully because it can get very confusing and frustrating especially when you must reference data from other parts of your program. Check out the difference of local and global variables, variables with the same name can have different values in different objects.

This report is generated from the main Edit Menu, Show Object Information.

Information about object: objGrams

Sprite: sprite0 // name of the sprite that you created in the editor to use for the button
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>

Create Event: // happens once when the 'game' first starts

execute code: // this means to select 'Execute a piece of code' (a script) from the menu

grams = 100; // set a default start value for the variable 'grams' other than 0

Mouse Event for Left Button: // happens whenever you left click the 'Grams' button

execute code:

oldgrams = grams; // copy the current value of grams to another variable for safe keeping

grams = real(get_string("Weight in Grams",string_format(grams,6,3) )); // THIS IS THE POP-UP BOX FOR DATA

if grams < 1 then grams = oldgrams; // prevent math errors if 0 is entered


Draw Event: // happens every time the screen is refreshed, code must be here to be visible on screen

at relative position (0,0) draw image -1 of sprite sprite0 // one of the draw menu selections

execute code:

draw_text(x+2,y+6,string_format(grams,6,3)+" Grams of Weight"); // draw info on top of button

ounces = grams * 0.0352739619; // a conversion formula

pounds = floor(ounces/16); // get the whole number from the division

if pounds > 0 draw_text(x+2,y+38,string(pounds)+" Lbs. "+string_format(ounces-(pounds*16),6,3)+" Oz.");
else draw_text(x+2,y+38,string_format(ounces,6,3)+" Ounces");
// draws additional info beneath button

My apology if this gave non-programmers a migraine. .conf
User avatar
Brian
WRA2 Member
WRA2 Member
Posts: 496
Joined: Fri Feb 08, 2008 6:02 am

Re: Need a Parachute Calculator?

Post by Brian »

thank you! this should be adequate for when i attempt to make a simulator.
Ascender Water Rockets
http://ascenderwaterrockets.weebly.com/
https://www.youtube.com/channel/UCS2NHXS-VFxEux70DCINR0w