Click to read sign posts

Hi guys,
i just tried messing with the click event and found out that you can click on signs to read their content with this very simple code in a npc in the first level of your world:

Visit Graal Classic Adventure to try it out!

Feel free to use this!

(Some part of me believes this must have already been done by someone else, but I can’t find anything on this forum about it)

// NPC made by Fredi
if (playerenters){
 toweapons -sign_click
}

if (mousedown && isweapon) {
 if (leftmousebutton){
   for (i=0; i<signscount;i+=1){
   if (mousex-signs[i].x <2 && mousey-signs[i].y<1 && mousex-signs[i].x>=0 && mousey-signs[i].y>=-1)
   {
    say i;
   }
  }
 }
}

Nice work, good to see you getting creative.

I’ve got tons of ideas, but setting everything right on old levels is a real hassle so I had to bother you guys for a while :stuck_out_tongue:

I’ll try adding some more interactivity to the game once I get to learn the v2.2.2 capabilities. (I used to code on 1.39-1.41)

[code]if (playerenters) toweapons -sign_click;

if (mousedown && isweapon) if (leftmousebutton) for (i=0; i<signscount;i+=1) if (mousex-signs[i].x <2 && mousey-signs[i].y<1 && mousex-signs[i].x>=0 && mousey-signs[i].y>=-1) say i;[/code]

huehue

I never would have thought that “say i” works like that.

[code]if (playerenters) toweapons -sign_click;

if (mousedown && isweapon) if (leftmousebutton) for (i=0; i<signscount;i+=1) if ((mousex-signs[i].x) in |0,2| && (mousey-signs[i].y) in |-1,1|) say i;[/code]
huahua

Does putting it this way give any form of optimization?

Nope. I think it all gets compiled down to the same thing. If you want to optimise the script, try having it exit the for loop after the if conditional is met.

Nope. Graal isn’t that smart.

Spooon’s is 100 “instructions” and 189 total bytes. tricxsta’s is 72 instructions and 145 bytes. In Graal terms, tricxsta’s will actually execute faster, though the difference is going to be small.

GS1 is an interpreted language rather than compiled (like PHP) afaik. So the length and complexity of the script does matter.

Compiling into bytecode is still compiled.

Gs1 never compiled into bytecode. The scripts are sent plaintext from server to client. The client then interprets the text. Everytime you surf to a PHP page, the server has to compile it in real time (unless you use addons), GS1 works the same way as every client needs to interpret the text sent from the server when connecting. Gs1 scripts aren’t stored/cached like gs2 is.

There’s a difference between pre-compiled languages and realtime interpreted, that’s all I’m saying. :slight_smile:

I wasn’t thinking about the fact that outdated shit is still being used here. Of course I know that 2.22 doesn’t do it the same way, although I wouldn’t be so sure that it isn’t compiled into bytecode. And how the fuck did you double post without annoying auto-merging?

Since GS1 is probably made by Stefan himself (back in the days), I wouldn’t doubt that it would be inefficient piece of turd. The script interpreter loop is what causes the 99% CPU usage in pre 2.31 clients.

The reason the posts wasn’t auto-merged was because I used the tapatalk client on my iphone which bypasses the auto-merge script.

No matter what I say about graal, it will always be wrong.

Who determined this? It’s more likely that it’s the primary APPLICATION loop that’s doing this, as is common among novice game programmers.

http://wiki.graal.net/index.php/Creation/Dev/Releases/Client/2.3

I remembered reading this in the context of scripting, but apparently not. It doesn’t say which timer it’s about.