Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Moru

Pages: 1 [2] 3 4 ... 101
16
Static is not important to learn in the start though.

Quick info is that STATIC is similar to LOCAL except the information stays in the variable until the program shuts down.

This means that a function can have variables that retains the information for each call. For example a counter of how many times the function has been called so a recursive function knows when to stop calling itself.

Another use could be a function that paints an object on screen. The function could be called with
Code: [Select]
draw_turtle("init", x, y) first time and save the location x and y as static variables. The second time you call the function it would be enough with
Code: [Select]
draw_turtle("forward")
draw_turtle("turn_left")
because it remembers the location from the last call. (turtle grafics from really old-school basic :-)

17
GLBasic - en / Re: Question for make a Wrapper
« on: 2013-Apr-01 »
There are links all over the boards about how to do this, just search for "header". This is one of the files I found: http://www.glbasic.com/files/headers.rar

I don't know when it was updated though since I have no clue how to do this myself :-)

18
Here is code for another way of doing it I think:
http://www.glbasic.com/forum/index.php?topic=6869.msg55619#msg55619

I would suggest to stay with one sprite sheet since that improves speed on some platforms. Ofcourse this means sprite collisions will be more work to set up...

19
Thankyou CW, I totally forgot to write that part of my post :-)

20
Yes, all examples are done as simple as possible. This often means leaving out the variable declarations.

Explicit declarations are a pretty late addition to GLBasic so all old examples will need this.

21
GLBasic - en / Re: SELECT - CASE limit ?
« on: 2013-Mar-31 »
Always run with debugger on. There is no reason not to use the debugger, that's what it's there for. Exactly this problem. You can't complain that it's not doing it's job if you don't use it :-) There is no way the compiler can catch this error anyway and for speed reasons you will have to check for this error yourself if you want to avoid it.

22
GLBasic - en / Re: SELECT - CASE limit ?
« on: 2013-Mar-30 »
No, there is nothing wrong with a case that has no target. If you want something to always happen if there is no matching case, you need to use DEFAULT as the last CASE.

23
GLBasic - en / Re: SELECT - CASE limit ?
« on: 2013-Mar-30 »
When I try your code with stop1 = 17 I get problems. If I set stop1 = 55 I have no problems. If you set a breakpoint (F9) just before the select code and then step through (ctrl+F10) you will see what really happens, can't say more without having your complete source.

24
GLBasic - en / Re: SELECT - CASE limit ?
« on: 2013-Mar-30 »
Hello!

If you activate debugging you will see that you are out of dim-array. This means you have too little space for your array.

DIM arr_icons[5][3];    <--- change to [5][4] to make space. Arrays start counting from 0 so 4 spaces means 0 - 3 is possible

25
GLBasic - en / Re: TCP over the internet
« on: 2013-Mar-28 »
I wrote it with version 7.1 and it worked fine last time I tried it. But as I said, this works on *most* routers. Not all :-)
Quake 2 was using something similar to this and that worked fine already then.
The linux guys were very surprised when their painstakingly secured firewall suddenly just let through traffic from outside of the network into the quake 2 server :-)

The example is not totally failsafe, you have to set it up and start it at the same time to see the effect so best is to use a remote control like Teamviewer to controll the other side so you see that something actually happens. And both endpoints can be behind a residential firewall.

26
GLBasic - en / Re: TCP over the internet
« on: 2013-Mar-28 »
Do you have any UDP tunnelling code anywhere ?

I thought I had but that wiki is down. But really, it's just that simple. Send UDP to other client. Send UDP back. The second or third attempt will go through the router just fine. (Not the first attempt, that will get blocked until both have send one packet each).

You also have to make sure you keep the connection alive by sending a packet every few seconds. Times are different depending on router so might need some research.

My testcode, not tested for years:

Code: [Select]
// --------------------------------- //
// Project: NetUDPThruRouter
// Start: Tuesday, September 15, 2009
// IDE Version: 7.104

// Works if you send a message from inside the firewall to the outside IP of the other client
// And then send a message from that client on the outside of the firewall to the inside.
// Both clients can be behind a firewall.


GLOBAL sock%               // The socket connection
GLOBAL port% = 15000       // Port number to use

LOCAL ok%, ip%, rv%, msg$
LOCAL myip$
LOCAL destip$
LOCAL timeout
LOCAL src_ip%, src_port% // The ip-address and port of the last packet

myip$ = NETGETIP$()        // Get our local IP just for the show
log("Our IP: "+ myip$)

STDOUT "\nDestination IP: "
destip$ = STDIN$()
// Just for less typing when testing
IF destip$ = "" THEN destip$ = "10.10.0.11"

ok = SOCK_INIT()    // Init network
IF ok
    sock = SOCK_UDPOPEN(port)    // Get the socket so we can send/recieve on the port
    IF sock <> -1
SOCK_SETBLOCKING sock, FALSE // Set socket to blocking(true), wait until message was sent or recieved

        ip = SOCK_GETIP(destip$) // Convert the string to an integer IP
        // Send 32 packets, waiting one second for an answer between each send
        FOR n = 0 TO 31
            log("Sending message: "+"Hello from "+myip$+" To: "+destip$)
            ok = SOCK_UDPSEND(sock, "Hello from "+myip$, ip, port)
            IF ok <> -1
                log("message sent with "+ok+" bytes")
                timeout = GETTIMERALL() + 1000      // Start timer for one second
                WHILE rv <> -1 AND GETTIMERALL() < timeout
                    rv = SOCK_RECV(sock, msg$, 999)
src_ip = SOCK_GETREMOTEIP(sock)
src_port = SOCK_GETREMOTEPORT(sock)
                    IF rv>0 THEN log("message recieved: ["+src_ip+"]["+src_port+"]["+msg$+"]")
                    IF rv=-1
                        log(NETGETLASTERROR$())     // Didn't work, tell user why
                        SOCK_CLOSE(sock)
                    ENDIF
                WEND
            ELSE
                log(NETGETLASTERROR$())
            ENDIF
        NEXT
    ELSE
        log(NETGETLASTERROR$())
    ENDIF
ELSE
    log(NETGETLASTERROR$())
ENDIF
KEYWAIT



FUNCTION log: str$
    STDOUT "\n"+str$
ENDFUNCTION

27
GLBasic - en / Re: Winsock error 10035
« on: 2013-Mar-28 »
Not everyone are perfect with English. You would be surprised to learn how many coders that use google translate to speak to others over the net. This can cause very rough language sometimes, totally different tone to what the user was expecting to say.

28
GLBasic - en / Re: TCP over the internet
« on: 2013-Mar-28 »
I think most routers will kill an inactive connection. Send a message now and then to keep it alive.

29
GLBasic - en / Re: TCP over the internet
« on: 2013-Mar-27 »
There is no need to do port forwarding or open up ports in most routers if you use UDP hole-punching. The only thing you need to do is one of the computers needs to know the others IP-number and start sending packets. The other one just sends packets "somewhere" as long as it's the same port number. Suddenly the packets from the first computer will go thru to the second computer.

If one computer is using a certain port for sending, the router opens up a tunnel back to that computer for incoming packets. Some routers demands that you send to the same IP-number as you recieve from but most don't even bother checking this.

30
GLBasic - en / Re: Hexagon Gameboard Engine
« on: 2013-Mar-27 »
If you download mappy and unpack it you will find some .htm files with instructions and formulas at least for displaying hexagonal maps and how to use them for accessing surrounding tiles.

http://www.tilemap.co.uk/mappy.php

Pages: 1 [2] 3 4 ... 101