help for beginners

84 views
Skip to first unread message

אליהו

unread,
Jun 18, 2016, 6:46:30 AM6/18/16
to Pawn Scripting Language
i am starting to learn pawn , i have a bit background in other languages and i read that is like a c syntax , i am following Pawn_Language_Guide.pdf  and i have trouble with the string examples that are not working, i want to know how to iterate over a string like c , 
somehting like 

string[] = "something"
new i = 0 
for( i = 0 ; i < strlen(string) ; i++){
        printf("%c" string[i])  
}

thanks!


Brian Deters

unread,
Jun 18, 2016, 10:54:15 PM6/18/16
to Pawn Scripting Language
one difference from C is the packed vs unpacked strings. You've used the unpacked [] indexing operator to declare and iterate the array, but you've initialed it with a packed "" constant. One fix would be to use the unpacked string constant like 'something'  and another fix is to use the packed operator when indexing the string which looks like string{i}

-Brian

אליהו

unread,
Jun 20, 2016, 8:24:11 AM6/20/16
to Pawn Scripting Language
thanks Brian ! 
another question if i want to get user input into  a string and  getvlues() , and iterate over the characters it's the same ?
by the way there is more documentation about pawn that you can recommend me? 

Brian Deters

unread,
Jun 20, 2016, 8:32:13 PM6/20/16
to Pawn Scripting Language
It depends on the method of getting user input. I have the VM running in a small microprocessor without a keyboard, so I didn't even implement any console input. Assuming you're using this to synchronously get user input:
getstring(string[], size=sizeof string, bool:pack=false)
You can pass a packed or unpacked array, but if you want the returned string to be packed, you must set the pack parameter, otherwise it will be unpacked as it defaults to false.

I think the "A tutorial introduction" section in the Pawn Language Guide does a very good job of walking through most of the concepts any beginner will need. I highly suggest reading through it all, if not even following along with the code yourself.

-Brian

אליהו

unread,
Jun 21, 2016, 4:29:12 AM6/21/16
to Pawn Scripting Language
ok thank you very much Brian !!

On Saturday, June 18, 2016 at 1:46:30 PM UTC+3, אליהו wrote:
Reply all
Reply to author
Forward
0 new messages