Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

API functions

okay well.. this is a scripting question and... another question to go along with it.. first off...

Can i use any of the API Functions such as the draw Arc API in the GDI32, I have the API call in Visual basic which is:

Public Declare Fucntion Arc Lib "gdi32", Alias "arc" _
(ByVal hdc as long, ByVal X1 as long, ByVal Y1 as long, _
ByVal X2 as long, Byval Y2 as long, Byval X3 as long, _
Byval Y3 as long, Byval X4 as long, byval Y4 as long) as long


How would I, if possible that is. How would I use that API call in RGSS?

And the 2nd part is. Does anyone know where I can get a list of API calls, and possibly give me a quick but helpful explanation on how to use them in RGSS. thank you :)
 
Sure, you can use. You just have to know which function you want to execute, the number and types of arguments you have to pass and the DLL in which this function is declared. To know all those API commands, the DLLs and requirements, go here (the MSDN site, there´re some helpful info). To use them inside Ruby you must use the Win32API class. I´ve explained some of the basic use here. Also, the Win32API class is better explained here, so CLICK ME xD
 
Right on Thank you :D

so this arc function just asked about would i call it like this:



DrawArc = Win32Api.new("gdi32","Arc",['i','i','i','i','i','i','i','i','i',],['i'])

But then how would i call that within say... Scene_Map in the bottom right corner. Just to draw a GUI?
 
Hmm.... I don´t know sufficiently to answer you with assurance, but in this case, to draw any image on the screen, with GDIPlus, to create a pen or vector object, and after that use it as an argument for the creation of a Graphic object. With this graphic object you can call a function that draws the line on the screen. If you want to draw it inside the game form, that would become even more difficult to implement... Maybe you should do that via RGSS, and mess a little with the Bitmap class. It could be more reliable and easier...

I can´t say so much thing, because i´m trying to learn more on that to make my own API calls correctly... And believe me, that´s not easy... xD
 
lol its all good Ill keep messing around with that to try figureing out. But you've help quiet abit actually. Just... i got another small question to ask ya.. if you dont mind.

There are plenty of Keyboard Input scripts out there.. Just all of them are extremly long. I know i could just copy and paste it.. but I rather know whats going on with it. So I figured Id try creating one. use the API calls of course. I just have two different buttons right now.. But can you tell me if this looks correct or if you could see anything wrong with it. I run it and I get an error saying cannot convert Array to String.

here is the script so far.. I have used VERY little of it from a script i had printed out last year and lost alot of the pages.. just got the first two pages pretty much.. so please... if you wouldnt mind


module Input
@keys = []
@Pressed = []

Tab = 9
M = 77

GetKeyState = Win32API.new("user32","GetKeyState",['i'],['i'])
GetKeyAsyncState = Win32API.new("user32","GetAsyncState",['i'],['i'])

def Input.getstate(key)
return true unless GetKeyState.call(key).between?(0,1)
return false
end



def triggered?(key)
@keys = []
@keys.push(Input::M) & 0x01 == 1
@keys.push(Input::Tab) & 0x01 == 1
end

end
 
The last argument passed in the creation of a Win32API object MUST be a string, and in fact you´re passing an array. Use this code and everything will become well...
Code:
module Input
@keys = []
@Pressed = []

Tab = 9
M = 77

GetKeyState = Win32API.new("user32","GetKeyState",['i'],'i')
GetKeyAsyncState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')

def Input.getstate(key)
return true unless GetKeyState.call(key).between?(0,1)
return false
end



def triggered?(key)
@keys = []
@keys.push(Input::M) & 0x01 == 1
@keys.push(Input::Tab) & 0x01 == 1
end

end
 
Right on thank you buddy :D Now one question.. that dont regard scripting. The way you entered your version of the script you have the light blue box around it. Others have it in a scrollable little window. and you also have that Show button how do you do those?
 
Actually still dont work :S it got rid of the error i did have before. Just ive tried using it like this:

if Input.triggered?(M)...

if Input.triggered?(77)...

and nothin works... I only needed a few extra buttons that is why I am tryin to make my own also .. cause i wanna learn
 
when you use include, it simply make all the method and constants in a module public and usable without calling the module name first example below

Code:
module ABC
   module_function
    def tester()
      return  self.name
    end
   VAR = 34
   VAR_M = 77
end

include ABC
#I can print VAR_M without calling ABC::VAR_M
print VAR_M
#if you don't use include ABC, then you will require to use ModuleName::Method/Constant
 
cool.. well .. i still get no where.. but could be, because of something that one of the users on here informed me about.. cause my version of the program is not legit.. and icausing an error for it to shut down.. so.. i dunno..
 
If you´re using the RMXP 1.01 you´ll not achieve the Win32API without errors, even if the syntax and use is correct. EB did an update on the Ruby version used in RGSS, and in the RMXP 1.02 all things works without errors. This is far all i know... Get the legal RMXP, and the problem will be solved.

BTW, the use of the module is simple... The keyboard keys are addressed accordingly with the ASCII table. You can pass decimals, octals or hexadecimal numbers to get a key value. For example, space is addessed with the number 0x20 (hexadecimal), so you could use:
Code:
if Input.triggered?(0x20)
# take an action
end

Here is the ASCII table, take a look:
http://img113.imageshack.us/img113/9899 ... ciixn5.gif[/img]
http://img180.imageshack.us/img180/8695 ... idajp5.gif[/img]

P.S.: Note that this is the table for the standard keyboard. The values for each key may be different depending on the type of keyboard you´re using (like mine ^^) or simply by country standards.
 
Right on That helps alot as well. K well.. I do actually intend on buyin the legal copy now. Just now i have a few questions about that and 1 other thing if possible till then.

1. Where can i purchase a legal copy?
2. Roughly how much would it cost?
3. Can i get it with English Translation or no?
if 'no' then how would i get it translated?

and the other question:
is it possible to get this update 1.02 till then? an where?
 
ANNNNNDDDDD wouldnt this work for changing the value of a variable:
if Input.triggered?(49)
$game_variables[1] = 1
elsif Input.triggered?(50)
$game_variables[1] = 2
elsif Input.triggered?(51)
$game_variables[1] = 3
elsif Input.triggered?(52)
$game_variables[1] = 4
end​
 
It would be easier to just make an array,
Code:
arr = []
arr[49], arr[50], arr[51], arr[52] = 1, 2, 3, 4
for i in 49..52
	$game_variables = arr[i] if Input.triggered?(i)
	break
end
But it would be even better to do away with the $game_variables completely.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top