Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Wiz's random question thread.

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
MultiColoredWizard
Come back, baby!
The Breastmaster



Joined: 01 Feb 2003
Posts: 1232

PostPosted: Mon Mar 08, 2004 2:02 pm    Post subject: Wiz's random question thread. Reply with quote

What exactly are readglobal and writeglobal supposed to do? I've seen them used a lot, but I've never really had any idea of how they're supposed to work.
(I'm guessing it's a mathematical thing, but, eh.)


Last edited by MultiColoredWizard on Mon Mar 08, 2004 2:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
Sephyroth
Renegade Rebel Redmage
Class A Minstrel



Joined: 04 Feb 2003
Posts: 644
Location: Schmocation

PostPosted: Mon Mar 08, 2004 2:11 pm    Post subject: Reply with quote

You basically use readglobal and writeglobal when you want to refer to a global var's ID # rather than its name.

Example:

Global variable(1,herohp1)

"var1:=readglobal(1)" is the equivalent of "var1:=herohp1". Basically, it returns the value of global variable #1.
"writeglobal(1,var1)" is the equivalent of "herohp1:=var1". It writes a value to global variable #1.
_________________
im realy ded Sad...
Back to top
View user's profile Send private message Send e-mail AIM Address
MultiColoredWizard
Come back, baby!
The Breastmaster



Joined: 01 Feb 2003
Posts: 1232

PostPosted: Mon Mar 08, 2004 2:28 pm    Post subject: Reply with quote

Okay, so by id it means the number(in your example, 1) , and the name is the.. name(in your case, herohp1)?

Er.. so is is read/writeglobal supposed to be faster?
Eh.. I still don't see why you should use it. I should experiment with it.
Back to top
View user's profile Send private message
Sephyroth
Renegade Rebel Redmage
Class A Minstrel



Joined: 04 Feb 2003
Posts: 644
Location: Schmocation

PostPosted: Mon Mar 08, 2004 2:51 pm    Post subject: Reply with quote

Think of it this way:

Say you have 10 heroes, and because you're trying to make a custom battle system, you use global variables for their hp. So global vars 1-10 would be the hp value for each of them, and vars 11-20 would be max hp values. Now say you wanted to have a script that recovers all of their hp.

If you used the *names* of the global vars, you'd have to write a line for each hero. Whereas if you used readglobal and writeglobal, you'd be able to do it with far less lines:

for(var,1,10) do,begin
write global(var,read global(var+10))
end

I'm not sure if using this makes the script faster or anything, but it makes it easier to organize your script in some situations.
_________________
im realy ded Sad...
Back to top
View user's profile Send private message Send e-mail AIM Address
Aethereal
SHUT UP.
Elite Designer
Elite Designer



Joined: 04 Jan 2003
Posts: 928
Location: Gone! I pop in on occasion though.

PostPosted: Mon Mar 08, 2004 5:01 pm    Post subject: Reply with quote

To quoth the plotscript dictionary, you can "use it to simulate fake arrays, in the old C-pointer style". Arrays are just a programming thing, so you might not really need to worry about it unless you want to become a really hardcore scripter like Retrogamer.
_________________
Back to top
View user's profile Send private message Send e-mail AIM Address
Minnek
Conjurer




Joined: 03 Jun 2003
Posts: 430
Location: Somewhere

PostPosted: Mon Mar 08, 2004 5:07 pm    Post subject: Reply with quote

Mmmm... hardcore scripting.

Anyway, just curious, is it faster to use a write/read command than to use the name of the variable? Wiz's comment piqued my interest in that area. XD
_________________
* SDHawk has joined #Minnek
SDHawk> AAAAAAAAAAAAAUUUUUUUUUGH
* SDHawk has left #Minnek (Leaving)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
MultiColoredWizard
Come back, baby!
The Breastmaster



Joined: 01 Feb 2003
Posts: 1232

PostPosted: Mon Mar 08, 2004 5:18 pm    Post subject: Reply with quote

Ah, Aeth explained arrays to me via AIM, and it has certainly piqued my interest.

Since maps are designated to having arrays for each tile(Like Aeth said, a grass tile next to 2 water tiles is just like 0 1 1), then would that mean you could use writeglobal and stuff for passability? It'd probably be a bit faster than checking passability..

I'm guessing that Retro did something like this for T-Blazers, which would explain why all of the platforms look the same(I wondered why the end of the level had that small platform, but like, no bottom).

But how did he do those wooden boards in the first level, which you can jump through? Did he just not make the head NPC blocked by the boards or.. something?

(and yes, I want to become a hardcore scripter)
Back to top
View user's profile Send private message
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Tue Mar 09, 2004 8:17 am    Post subject: Reply with quote

I use them a lot. It's very nice to have name-agnostic references. For example, if I've got sets of 3 global variables, with the first, second, and third variable serving the same purpose in each set, I just have to point to the appropriate set, and then move relative to that pointer -- I don't have to worry about whether it's "BillHP" or "MikeHP".

Um...yeah... My English teacher would kill me.

*zip*
Back to top
View user's profile Send private message
Cube
Dimensional Traveller




Joined: 02 Feb 2003
Posts: 294

PostPosted: Tue Mar 09, 2004 9:15 am    Post subject: Reply with quote

Yup, you'd mostly use the commands to obtain information dynamicly. I used them in the past for my Gem Combo system, and will use them in a game I'm making with Sew.

The Gem combo system I wrote back in October is a good example though, because it fakes multi-dimensional arrays. First, see this picture:



Notice it's a 6x6 grid, with different elements on it. Now, realise that each of those tiles are actually global variables, but I can call them by using a simple autonumber (Example: read_tile(2, 5), would tell me what's in the 3rd tile to the right, 6th tile down (I use 0 as the starting number)).

Basicly, I'm using 36 global variables for this. Finding which one in those 36 contains the specified number is rather easy when you used a simple equation. Also keep in mind that using a constant to keep track of WHEN the array starts is a good idea since the group of 36 variables might start at ID 47:

read global ((x+(6*y))+start)

I don't think I really need to explain what's going on in this equation. The x and y basicly work the same as it would with the maps in the OHR itself. The (6*y) part just obtains the row you're choosing from. A good way to see this is to actually visualise the table:

Code:

     0  1  2  3  4  5
 
0    0  1  2  3  4  5
1    6  7  8  9 10 11
2   12 13 14 15 16 17
3   18 19 20 21 22 23
4   24 25 26 27 28 29
5   30 31 32 33 34 35


To get (2,3), I need to multiply 6 by 3 which = 18. Then add 2. In the end, I get number 20 which matches up perfectly with the table. If the array of numbers starts at 47 for whatever reason, then just add 47 to all those numbers Raspberry!.

I want to say one more thing about the starting constant too. It's good to have because you'll be able to easily change which global IDs the table uses without changing a bunch of code (I have to do this all the time, so my global definitions are more tidy).

(The same can be applied in C++ and other programming languages as James once told me, but I prefer to use variable_name[][] rather than one gigantic array since I find it easier to work with Raspberry!.)
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Wed Mar 10, 2004 1:47 am    Post subject: Reply with quote

Ok, firstly, using arrays in plotscripting is not just for hardcore scripts. they're for anyone to use who already understands the basics. Anyone creating a custom battle engine would use lots of them to store data.

As for the question of speed, I think I can break down the way plotscripting works to arrive at an answer:

When you write

Hero1hp := 34

(or set variable (hero1hp, 34))

and

write global (1, 34)

You are executing 3 commands in each case. In the first case the commands are (if you call them that) set variable, int 1 (refering to global variable 1, don't worry about it), and int 34. In the second they are write global, int 1, and int 34.
The only difference is that you are swapping the set variable command (a math function) with write global (a hard coded function). So you would expect them to run at the roughly same speed.

I ran speed tests, because I was curious if there was any difference:

Test 1: 800 set variables per tick/frame (local)
speed: 6.3 frames a second.
Test 2: 800 set variables per tick (global)
speed: 6.3 frames a second.
Test 3: 800 write globals per tick
speed: 6.3 frames a second.

(rounded to nearest 0.1 frame/sec)

As you can see, they run at exactly the same speed.

On the other hand, refering to a global by name is only one command (type global) when writing read global (1) is 2 (type hard coded function, type int), so you may consider using names faster in this case.

However, any difference in speed would be so slight that it would only show up as a fraction of a frame/sec difference when used hunderds of times a cycle.

Answered your question, MCW?
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group