Sign in to follow this  
Followers 0
BJJ

New math problem

3 posts in this topic

I try make calculator to game and have problem with operation upon variable

My code dont calculate corectly :/

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt ('GUIOnEventMode','1')


$GUI = GUICreate("Crimson V1.0", 301, 226, 321, 237)
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit')
$tlo = GUICtrlCreatePic("C:\D & S\Prezes\Pulpit\www\AutoIT\projekt The Crims\1.jpg", 0, 0, 297, 225, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$sila = GUICtrlCreateInput(" ", 208, 8, 73, 21)

$defens = GUICtrlCreateInput(" ", 208, 40, 73, 21)

$kukly = GUICtrlCreateInput(" ", 208, 72, 73, 21)



$Start = GUICtrlCreateButton("oblicz", 48, 184, 113, 25, 0)
$Label1 = GUICtrlCreateLabel("                      Sila ", 56, 8, 132, 17)

$Label2 = GUICtrlCreateLabel("          Wytrzymalosc", 56, 40, 140, 25)

$Label3 = GUICtrlCreateLabel("          Ilosc kukiel w gangu", 56, 72, 140, 25)



GUICtrlSetOnEvent ($Start, '_Start')

GUISetState(@SW_SHOW, $GUI)

While '1'
Sleep ('150')
WEnd





Func _Start ()
MsgBox ('0','Crimson V1.0','Kazda kulka powinna miec ' & _Result () & ' sily ', '0')

EndFunc



Func _Result ()
    

$sila = GUICtrlRead($sila)
$defens = GUICtrlRead($defens)
$kukly = GUICtrlRead($kukly)



$srednia = (($sila + $defens) /2)

$wynik = ($srednia / $kukly)

Return $wynik
EndFunc



Func _Exit ()
Exit
EndFunc

Share this post


Link to post
Share on other sites



Math seems correct. I'm not aware of what your going for though. However I see that your using the same variable for your control and your read. This will result in incorrect results on any future read.

ie:

$sila = GUICtrlRead($sila)

This is saying take the data read from the control and set the variable of the control to the data. Now the control does not relate to a variable because it's been reset. Any time you read the control again it will be trying to read the data. (read the read the data ?!?)

Share this post


Link to post
Share on other sites

ok i change this bad part of code to

Func _Result ()
    

$sila1 = GUICtrlRead($sila)
$defens1 = GUICtrlRead($defens)
$kukly1 = GUICtrlRead($kukly)



$srednia = (($sila1 + $defens1) /2)

$wynik = ($srednia / $kukly1)

Return $wynik
EndFunc

Now work greate but maybe is simple way to this ??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0